IMAGEVIEW SET HEIGHT BY PROGRAMME

Tanuj Kumar

Total Post:134

Points:940
Posted by  Tanuj Kumar
 1157  View(s)
Ratings:
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" />

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: Imageview set height by programme

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!