我告诉你我有以下代码
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/happy" />
但它太大了我需要缩小它,但是当我这样做时会发生以下情况
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="44dp"
android:layout_height="41dp"
android:src="@drawable/happy" />
您可以看到图像的某些部分丢失了,如果不发生这种情况,我怎么能缩小它呢?
答案 0 :(得分:1)
您需要调整原始图像的大小,或者您可以使用ImageView(具有scaleType参数)并使其可点击,例如。
<ImageView
android:id="@+id/smiley_iv"
android:layout_width="44dp"
android:layout_height="41dp"
android:src="@drawable/happy"
android:scaleType="centerInside"
android:clickable="true" />
在这种情况下,您可能想要添加自己的背景选择器(对于按下状态等),显然您需要通过xml或以编程方式添加onClick回调。