简体   繁体   中英

How to set Width of the image (in ImageView) without changing the width of the ImageView?

What I am trying to do is change the width of the image in a ImageView without affecting the width of ImageView.

    ----------------------------------------------------------------
    |                                                              |
    |                                                              |
    |         ----------------------------------------------       |
    |         |                                            |       |
    |         |                                            |       |
    |         |    this is the image( change its width)    |       |
    |         |                                            |       |
    |         ----------------------------------------------       |
    |                                                              |
    |      this is imageView the width mustnt change               |
    ----------------------------------------------------------------

How can I achieve this ? Please Help?

You can use ScaleType for that. Like,

imgV.setScaleType(ImageView.ScaleType.CENTER_CROP);

and you can specify Padding property too.

see the link it might help you.

Android ImageView adjusting parent's height and fitting width

ImageView and image are not different. To show an image in an Android device we are using an ImageView. If you want to show an image at the centre of something, then wrap the image view with some layout and set the image inside that layout with some padding all the side you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM