使Android源图像资源填充按钮区域

5

我能提供以下XML:

<ImageButton
    android:id="@+id/SwapTextButton"
    android:layout_width="match_parent"
    android:layout_height="45dp"
    android:layout_weight="0.5"
    android:background="@drawable/my_gradient_button"
    android:scaleType="fitCenter"
    android:src="@drawable/extended_text" />

它输出一个看起来像这样的按钮:

Button text too small

有没有办法增加src资源所占用的大小?我的意思是保持src在按钮区域内,但使其比现在更大。

我尝试过更改scaleType,但任何其他设置都会导致src资源在按钮边界外显示其部分内容(也就是说它变得太大)。

我做了一些研究,似乎有基于java的解决方案,但理想情况下,我希望保持xml中的解决方案。

有人能提供修复建议或指引我正确的方向吗?

谢谢

2个回答

4
<ImageButton
android:id="@+id/SwapTextButton"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="0.5"
android:background="@drawable/my_gradient_button"
android:scaleType="fitXY"
android:src="@drawable/extended_text" />

尝试一下,将scaletype设置为fitXY,这样可以“填充”您的ImageButton。

非常感谢!我确信以前试过了,但现在它有效了。非常感激。 - Andy A

0
这对我有用:
android:padding="0dp";

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接