Android: How to prevent image from being scaled in ImageView or ImageButton?

后端 未结 3 1513
难免孤独
难免孤独 2020-12-29 13:21

How can I prevent my bitmap from being scaled automatically in an ImageView or ImageButton if the view or button is stretched using \"fill_parent\" or using \"weight\"?

3条回答
  •  佛祖请我去吃肉
    2020-12-29 13:32

    Simply modify your drawable, apply a larger transparent background. Say my drawable in hdpi is 41*48 px icon.png . I created a new image 60*60 px with a transparent background , copy-paste the previous icon.png and save under the same name. This way you don't need to touch your layouts .

    Then you can check the button zone larger if you apply a non transparent android:background:

    
    

    Apply the previous and new drawable to android:src , you should clearly see ImageButton area.

    By the way, I am running the app in compatibility mode.

提交回复
热议问题