Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing height and width of imageview in android

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


}
like image 376
yuva ツ Avatar asked Feb 25 '13 15:02

yuva ツ


People also ask

What is ImageView in android?

Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling.


2 Answers

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.

like image 73
Nickolaus Avatar answered Sep 21 '22 13:09

Nickolaus


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...

like image 42
Karan_Rana Avatar answered Sep 22 '22 13:09

Karan_Rana