我试图在我的布局中使用9补丁图像作为按钮。 9补丁图像按钮仅适用于最右侧的按钮(ID为tab_btn_C)。我不确定是什么问题。图像似乎是正确的,我用drawable-hdpi / drawable-mdpi文件夹中的.9.png保存了正确的文件名。
另一个奇怪的事情是 - 如果我使用ImageButton而不是Button,则下面的布局似乎有效。任何帮助表示赞赏。
布局文件
<LinearLayout
android:id="@+id/questions_list_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/logo"
>
<Button
android:id="@+id/tab_left_btn"
android:layout_height="wrap_content"
android:layout_width="100dp"
android:background="@drawable/tab_btn_left"
android:layout_marginLeft="5dp"
android:text="A"/>
<Button
android:id="@+id/tab_middle_btn"
android:layout_height="wrap_content"
android:layout_width="100dp"
android:background="@drawable/tab_btn_middle"
android:text="B"/>
<Button
android:id="@+id/tab_btn_C"
android:layout_height="wrap_content"
android:layout_width="100dp"
android:background="@drawable/tab_btn_right"
android:text="C"/>
</LinearLayout>
选择器文件
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_left_active"
android:state_pressed="true" />
<item android:drawable="@drawable/btn_left" />
</selector>
答案 0 :(得分:0)
事实证明,9补丁图像的创建方式有问题。我再次创建它,并修复了它自己。我使用此http://android10.org/index.php/articlesother/279-draw-9-patch-tutorial获取有关创建9补丁的详细说明。
谢谢!