How can I resize a ImageView from my XML?

59 views Asked by At

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);
2

There are 2 answers

0
Hiren Patel On BEST ANSWER

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

0
Dhruv On

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);