android ImageButton 不拉伸(stretch)图像

标签 android imagebutton image-resizing

如何防止 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" />

我得到以下效果:

enter image description here

图像是 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/

相关文章:

安卓设备电话号码

android - 二进制 XML 文件行 #45 : Error inflating class ImageButton onload but only on some devices

javascript - 在 JavaScript 中调整和压缩上传的图像

java - 我的 Android 应用程序崩溃了,即使我捕获了它所说的导致崩溃的异常

android - 在不同的 drawable 文件夹中位图需要多少内存

android - 如何检测我的应用程序的用户界面已移至后台?

java - VideoView "is loaded"监听器?

java - 图像按钮导致崩溃

html - 两张图片,一张调整大小,一张未调整大小

jquery-plugins - jQuery 文件上传不再调整图像大小