0

我认为这将是在线提供的快速解决方案,但没有运气。我有一个 .9.png 按钮。我有不同大小的文本字段,例如:“Chapters”或“Bb”或“Eb”。我希望 ImageButton 调整为文本的大小。无论文本如何,按钮都保持相同的大小。我可以使用常规按钮执行此操作,但不能使用我的 ImageButton。我忽略了什么?只有我的第二个应用程序。

这是 XML:

     <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/chapters"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/btn_layout_height"
        android:textSize="@dimen/text_size"
        android:background="@drawable/button"
        android:text="@string/chapters" /> 

这是维度文件:

<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">1dp</dimen>
<dimen name="activity_vertical_margin">1dp</dimen>
<dimen name="text_size">15sp</dimen>
<dimen name="btn_layout_height">40dp</dimen>

.9.png 文件位于 res/drawable 中。

我在 XML 文件中尝试了布局填充,并在 Draw9Patch 工具上调整了可拉伸和填充区域。按钮的尺寸为 100 x 27。

这是 .9.png 文件

4

0 回答 0