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

Ravindra Kushwaha
- 7,846
- 14
- 53
- 103

Ramya S
- 109
- 3
-
getLayoutParams() not setLayoutParams() – Madhur Feb 03 '16 at 10:28
-
You can use `DisplayMetrics` logic . Why using `Hard-Coded` Value ? – IntelliJ Amiya Feb 03 '16 at 10:39
-
Check http://stackoverflow.com/questions/3144940/set-imageview-width-and-height-programmatically – IntelliJ Amiya Feb 03 '16 at 10:55
5 Answers
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
-
-
Dear , its working well in my case. ImageView im = (ImageView)findViewById(R.id.imageView); im.getLayoutParams().height = 130; – Rajesh Satvara Feb 03 '16 at 11:48
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
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