在今天的项目中遇到这样一件事,就是给button设置一个背景图,但是明显发现图片被拉升,首先说明一点背景图很小。
android:layout_width="wrap_content"
android:layout_height="wrap_content"
设置的都是wrap_content。
然后去找ui,ui说不是他的问题,于是就自己找问题。
就去看button的源码


从图可以看出,Button 有一个默认的宽和高,也就是说,我们设置的宽和高不超过这两个值,相当于我们设置的无效。如果图片太小,则会变形。
解决办法:
(1)将minHeight和minWidth都设置为0
(2)用ImageButton代替 Button
网友评论