Home > DeveloperSection > Forums > Imageview set height by programme
Tanuj Kumar

Total Post:134

Points:940
Posted on    October-11-2014 12:53 AM

 Android Android  Mobile Development 
Ratings:


 1 Reply(s)
 838  View(s)
Rate this:
I want to set the height of the image view programatically in gridview. I used below code-

imageview.getLayoutParams().height = height;

This is working fine in android version 4.3 and higher but not working in android version 4.2 and below. I can't find the issue. Any help please.

ImageView in xml-

<ImageView

 android:id="@+id/item_image"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:scaleType="centerCrop"

 android:background="@drawable/top_radius" />



Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    October-11-2014 12:55 AM

This is a simple way to set dimensions of imageview.


ImageView iv = (ImageView)findViewById(R.id.imageview);

int width = 60;

int height = 60;

LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(width, height);

iv.setLayoutParams(parms);


Don't want to miss updates? Please click the below button!

Follow MindStick