相关疑难解决方法(0)

如何获得android.widget.ImageView的宽度和高度?

????????????????????????????????????????????????   ^
? ImageView    ????????????????                ?   |
?              ?              ?                ?   |
?              ? Actual image ?                ?   |
?              ?              ?                ?   |60px height of ImageView
?              ?              ?                ?   |
?              ?              ?                ?   |
?              ????????????????                ?   |
????????????????????????????????????????????????   
<------------------------------------------------>
                   90px width of ImageView
Run Code Online (Sandbox Code Playgroud)

我有一个默认高度和宽度的图像视图,图像存储在数据库中,我想根据Imageview高度宽度缩放图像.因为我不希望它给出默认值,因为当我改变它的高度和宽度时我也必须在代码中更改它.

我试图获得ImageView的高度和宽度,但在两种情况下都返回0.

int height = ((ImageView) v.findViewById(R.id.img_ItemView)).getHeight();
Run Code Online (Sandbox Code Playgroud)

即使它有默认的高度和宽度,这也会返回0

height android image width

270
推荐指数
7
解决办法
14万
查看次数

如何获取ImageView的高度和宽度?

我正在尝试获取 ImageView bot 的高度和宽度,它返回 0

public class FullScreenImage extends FragmentActivity {
    ImageView full_view;
    int width;
    int height;
    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);

        setContentView(R.layout.full_screen);

        full_view   = (ImageView)findViewById(R.id.full_view);

        Bundle bundle=getIntent().getExtras();
        byte[] image=   bundle.getByteArray("image");

        width       =     full_view.getWidth();
        height      =     full_view.getHeight();

        Bitmap theImage = BitmapFactory.decodeByteArray(image, 0, image.length);
        Bitmap resized = Bitmap.createScaledBitmap(theImage,width , height, true);

        full_view.setImageBitmap(resized);
    }


}
Run Code Online (Sandbox Code Playgroud)

请帮助我,如何从 ImageView 中找到它?

android android-imageview

-1
推荐指数
1
解决办法
1468
查看次数

标签 统计

android ×2

android-imageview ×1

height ×1

image ×1

width ×1