Rah*_*tte -1 android android-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 尚不知道视图有多大,因此将大小设置为零。实际尺寸是在布局阶段计算的,该阶段发生在构建之后但在绘制任何东西之前。您可以使用该onSizeChanged()方法在已知值时通知它们,或者您可以稍后使用getWidth()和getHeight()方法,例如在onDraw()方法中。
| 归档时间: |
|
| 查看次数: |
1468 次 |
| 最近记录: |