获取和设置ImageView的宽度和高度
1 minute read
不能用imageview.getWidth() 和 imageview.getHeight() 来直接获取高和宽。
获取方法:
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.image);
//(BitmapDrawable)getResources().getDrawable(R.drawable.image).getBitmap();
int width=bitmap.getWidth();
int height=bitmap.getHeight();
设置方法:
imageView.setImageResource(R.drawable.image);
LayoutParams params = imageView.getLayoutParams();
params.height=200;
params.width =100;
imageView.setLayoutParams(params);