【问题标题】:Android 9 patch image not showing up when I use Button使用 Button 时未显示 Android 9 补丁图像
【发布时间】:2012-03-21 21:58:23
【问题描述】:

我正在尝试在我的布局中使用 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>

【问题讨论】:

  • 你能上传9补丁文件吗?

标签: android imagebutton nine-patch


【解决方案1】:

事实证明,9 补丁图像的创建方式存在问题。我再次创建它,它自己修复了。我使用这个http://android10.org/index.php/articlesother/279-draw-9-patch-tutorial 来获取创建 9 补丁的详细说明。

谢谢!

【讨论】:

    猜你喜欢
    • 2011-05-15
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多