如何设置图像progragmaticall的宽度?
这是我的代码,
txtone = (ImageView)findViewById(R.id.imageView);
txttwo = (ImageView)findViewById(R.id.imageView2);
height = metrics.heightPixels;
width = metrics.widthPixels;
if (height == 800 && width == 1217) {
int a = txtone.getMeasuredWidth();
txtone.getLayoutParams().width = 280;
txttwo.getLayoutParams().width = 280;
txtthree.getLayoutParams().width = 280;
txtone.requestLayout();
txttwo.requestLayout();
txtthree.requestLayout();
答案 0 :(得分:1)
在实际初始化之前,您尝试使用txttwo
txtthree
之一。当你打电话
null
txttwo.getLayoutParams().width = 280;
txtthree.getLayoutParams().width = 280;
至于您的代码,您没有初始化txtthree