如何将图像按钮中的图像拉伸到图像按钮的整个区域?

use*_*993 22 android image stretch imagebutton

这张图片可以帮助您理解我的问题:

这是一个

我想把里面显示的图像拉伸ImageButton到整个区域ImageButton.正如您所看到的,数字1的图片只占大约95%,ImageButton你也可以看到它的边界ImageButton.

我还是想保持图像按钮的样式

这是我使用ImageView的方式:

<ImageButton
    android:id="@+id/secondActivityBbuttonDownRight"
    android:layout_width="0dip"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:scaleType="fitStart"
    android:src="@drawable/111" />
Run Code Online (Sandbox Code Playgroud)

我想我发现了我的问题.我需要一个只包含图像并具有单击效果的自定义组件.

Leo*_*dos 58

ImageButton是ImageView.
如果您希望图像填充按钮而
不是设置android:scaleType="fitXY",则您设置的图像android:src将被拉伸以填充整个图像按钮.

ImageButton在您的图像和填充下有一个背景.
如果您不想要背景
设置android:background="@android:color/transparent".
如果您不想填充
设置android:padding="0"或设置背景而不填充.


zac*_*rav 7

你也可以使用

android:scaleType="centerCrop"
android:padding="0dp"
Run Code Online (Sandbox Code Playgroud)


dan*_*117 5

android:scaleType="fitXY" 测试并正常工作。


dug*_*ggu 2

使用下面的代码:-

<ImageButton
        android:id="@+id/secondActivityBbuttonDownRight"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:scaleType="fitStart"
        android:background="@drawable/111" />
Run Code Online (Sandbox Code Playgroud)