0

I tried IMAGEVIEW.getLayoutParams().height = 200. But it is not changing correctly. Is there any other possible way, please give suggestion.

Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103
Ramya S
  • 109
  • 3

5 Answers5

2

use this

 LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(200, 200);
    yourImageView.setLayoutParams(layoutParams);
Madhur
  • 3,303
  • 20
  • 29
1
_image_view.getLayoutParams().height = 30;

Hope this helps.

Very Important.

If you're setting the height after the layout has already been 'laid out', make sure you also call this :

_image_view.requestLayout()
Rajesh Satvara
  • 3,842
  • 2
  • 30
  • 50
1
 ImageView mImageView = (ImageView)findViewById(R.id.image_view);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(100, 100); // Paramters are (width, height) in pixels
            mImageView.setLayoutParams(layoutParams);

If you want multiple resolution compatibility,

 LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams((int)(getResources().getDimension(R.dimen.image_with)),
                (int) getResources().getDimension(R.dimen.image_height));

dimens.xml under resource

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="image_with">100dp</dimen>
    <dimen name="image_height">100dp</dimen>
</resources> 
Nithinjith
  • 1,775
  • 18
  • 40
0

If your imageview already shows the image,

Call:

image_view.requestLayout(); 
Gagan Sethi
  • 397
  • 1
  • 8
0

At First Check Set ImageView width and height programmatically

You can try with DisplayMetrics Logic .Its more perfect .

A structure describing general information about a display, such as its size, density, and font scaling.

   DisplayMetrics metrics = getResources().getDisplayMetrics();

   int DeviceTotalWidth = metrics.widthPixels;
   int DeviceTotalHeight = metrics.heightPixels;

   image_view.getLayoutParams().height= (int) (DeviceTotalHeight*5.25/100); // You can change from here

Another Way

    LinearLayout.LayoutParams layoutParams = new  LinearLayout.LayoutParams(200, 200);
    IMAGEVIEW.setLayoutParams(layoutParams);
Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198