in my application on button click i want to change size of imageview.when i click on one button i want to increase size of imageview by 5(each width and height).and on clicking of other button i want to decrease the size.i tried this. how can i do this?below is the code.its not working
public void increase(View v)
{
int height=imageView.getHeight();
int width=imageView.getWidth();
imageView.getLayoutParams().height = height+5;
int h=imageView.getHeight();
System.out.println("hhhhhhhhhh,,,,,,,,,,"+h);
System.out.println("width n hight..."+width+"and"+height);
}
Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling.
UPDATE:
Do this:
int height=imageView.getHeight();
int width=imageView.getWidth();
imageView.setLayoutParams(new LinearLayout.LayoutParams(height, width));
Suggesting your ImageView is located inside a LinearLayout you need to do this:
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imageView.getLayoutParams();
params.setHeight(XX);
params.setWidth(XX);
imageView.setLayoutParams(params);
I don't know if the syntax is perfectly correct, but basically this is how you do it, don't forget that you need to update your UI, in order to see any changes.
I use the following code for it:
your_image_view.getLayoutParams().height = 20;
Hope it helps u..
you can try the following alternate approach.. see if it works:
LayoutParams params = (LayoutParams) imageView.getLayoutParams();
params.width = 120;
params.height = 120;
imageView.setLayoutParams(params);
Although both the codes are almost same...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With