好的,我有一个按钮,它使用一个选择器作为它的背景。我将宽度和高度设置为 wrap_content。内容是我设置的一些文字。我希望按钮像 native 按钮一样围绕文本调整大小,但按钮很大,基本上看起来与其源图像一样大。按钮图像是 9-patch 图像,按钮 xml 位于相对布局内。我在这里缺少什么?
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/holo_btn" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/holo_btn" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/holo_btn" />
<item android:drawable="@drawable/holo_btn" />
</selector>
<Button android:id="@+id/btnTaskPriorityLow"
android:paddingLeft="@dimen/paddingSmallButton" android:paddingRight="@dimen/paddingSmallButton"
android:text="@string/strTaskPriorityLow"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/textViewCalColor"
android:layout_toRightOf="@+id/textViewPriority"
android:layout_marginTop="@dimen/marginTopAppt"
android:background="@drawable/button_holo_sel"/>
最佳答案
如果我知道你有一个巨大的 9-Patch 作为背景。
AFAIK,9-Patch 可以扩展但不能减少。因此,您可能必须编辑 9-Patch 以使其尽可能小。通常您可以将中心可拉伸(stretch)区域减少到一个像素。
关于android - 带有 9-Patch 背景的按钮不包含内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14414577/