我希望在Java Activty中从XML调整ImageView的高度和宽度(如何进行调整?
private ImageView imageView;
imageView = (ImageView) findViewById(R.id.imageView);
答案 0 :(得分:0)
通过 xml 设置宽度和高度:
<ImageView
android:id="@+id/imgLauncher"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/ic_launcher" />
您必须根据您的要求更改 android:layout_width =“”和 android:layout_height =“”。
设置宽度和高度 Java 代码:
private ImageView imgLauncher;
绑定视图
imgLauncher = (ImageView)findViewById(R.id.imgLauncher);
通过 LayoutParams
设置 Widht 和 HeigthimgLauncher.getLayoutParams().height = 20;
imgLauncher.getLayoutParams().width = 20;
设置 LayoutParams 后,刷新视图
imgLauncher.requestLayout();
完成强>
答案 1 :(得分:0)
只需在活动中添加代码
即可Display display = getWindowManager().getDefaultDisplay();
ImageView iv = (LinearLayout) findViewById(R.id.ivMyImage);
int width = 30;
int height = 30;
LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(width,height);
iv.setLayoutParams(parms);