![](/img/trans.png)
[英]How I can shrink an image (ImageView or ImageButton) without losing pieces of it?
[英]Android resize an ImageButton without losing the clarity of the image
我在相对布局中添加了一个ImageButton,我的xml代码是
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomePageActivity" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="132dp"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/book" />
</RelativeLayout>
由于log的width和height是wrap_content,因此图像很清晰,但是当我指定更大的width和height时,例如:
android:layout_width="80dp"
android:layout_height="80dp"
然后,当在AVD上运行时,图像按钮会变得不清楚。 有什么解决办法吗?
默认情况下, ImageView
/ ImageButton
将缩放图像以适合中心。
您可以使用android:scaleType = "center"
进行更改。 这将使图像保持其原始大小并保持居中。
如果图像不是对象的图片而是矩形,请将其转换为9色可绘制对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.