I want to resize (height and width) a ImageView from XML at my Java Activty how can I do that?
private ImageView imageView; imageView = (ImageView) findViewById(R.id.imageView);
Set Width and Height by xml:
<ImageView android:id="@+id/imgLauncher" android:layout_width="50dip" android:layout_height="50dip" android:src="@drawable/ic_launcher" />
You have to change android:layout_width="" and android:layout_height="" as per your requirement.
Set Width and Height Java Code:
private ImageView imgLauncher;
Bind view
imgLauncher = (ImageView)findViewById(R.id.imgLauncher);
Set Widht and Heigth by LayoutParams
imgLauncher.getLayoutParams().height = 20; imgLauncher.getLayoutParams().width = 20;
Refresh view after set LayoutParams
imgLauncher.requestLayout();
Done
Simply add code in your activity
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);
Set Width and Height by xml:
You have to change android:layout_width="" and android:layout_height="" as per your requirement.
Set Width and Height Java Code:
Bind view
Set Widht and Heigth by LayoutParams
Refresh view after set LayoutParams
Done