我将这个小布局定义为插入到我的应用程序的每个页面中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="@null"
android:src="@drawable/sa_info"
android:layout_alignParentRight="true"/>
我的 sa_info.png 是 118x118,但我希望它在屏幕上看起来小得多。如果我尝试将 imagebutton 的宽度和高度设置为所需的大小(比如说 48dp),那么当我运行应用程序时生成的图像将被裁剪到中心:
所以我必须获得所需结果的唯一方法是将图像本身缩放到所需的分辨率。 我做错了什么,有更好的方法吗?
最佳答案
尝试添加
android:scaleType="fitCenter" -> http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
android:adjustViewBounds="true" -> 如果您希望 ImageView 调整其边界以保持其可绘制对象的纵横比,请将此设置为 true。
关于Android:layout_width 和 height 裁剪我的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19976612/