如何防止 ImageButton 拉伸(stretch)图像?
使用这个 fragment :
<ImageButton
android:src="@drawable/prediction"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_horizontal"
android:scaleType="centerInside"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:contentDescription="some description"
android:text="@string/predict"
local:MvxBind="Click ExecuteQueryCmd" />
我得到以下效果:
图像是 64x64 png。
我想要的只是让 ImageButton 尊重分配给它的图像的原始宽度和长度,以及分辨率。基于 similar post 的建议是使用 Button,将其背景设置为图像,然后使用自定义选择器,但这听起来像是 hack。或者这是执行此操作的正确方法吗?
最佳答案
它对我有用
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:contentDescription="some description"
android:scaleType="centerInside"
android:src="@drawable/ci_icon"
android:text="@string/predict"
local:MvxBind="Click ExecuteQueryCmd" />
将你的图片放在android:src属性中
关于android ImageButton 不拉伸(stretch)图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20075350/