【问题标题】:Background drawable error背景可绘制错误
【发布时间】:2014-02-04 17:03:35
【问题描述】:

我有一个带有某种开关按钮的应用程序,它实际上是 2 个文本视图对齐在屏幕的中心,我遇到了问题,当我在 JB 设备中测试应用程序时它一切正常,但是当我在一些 GB 设备中测试,文本视图的背景被弄乱了。 这是 JellyBean 设备上的显示方式,应该是这样的:

这就是它在 GingerBread 设备上的显示方式:

知道会发生什么吗?

这些是 xml 文件的相关部分:

layout_activity.xml

<LinearLayout
        android:id="@+id/Layout_driver_status"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/Layout_Profile"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="20dp"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/tv_Libre"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/background_libre"
            android:paddingBottom="20dp"
            android:paddingLeft="40dp"
            android:paddingRight="40dp"
            android:paddingTop="20dp"            
            android:text="Libre"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#ffffff" />

        <TextView
            android:id="@+id/tv_NoDisponible"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/background_no_disponible"
            android:paddingBottom="20dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="20dp"       
            android:text="No Disponible"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#ffffff" />
    </LinearLayout>

可绘制/Background_libre.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:bottom="3dp">
        <shape android:shape="rectangle" >
            <corners 
                android:topLeftRadius="6dp"
                android:bottomLeftRadius="6dp"                
                 />
            <solid android:color="@color/libre_verde" />
        </shape>
    </item>

</layer-list>

drawable/Background_no_disponible.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:bottom="3dp">
        <shape android:shape="rectangle" >
            <corners android:bottomRightRadius="6dp" 
                     android:topRightRadius="6dp" 
                    />
            <solid android:color="@color/no_disponible_plomo" />
        </shape>
    </item>

</layer-list>

【问题讨论】:

    标签: android xml background drawable


    【解决方案1】:

    这是一个已知的错误。 12 及以下版本左右切换。

    像这样:

    <corners 
       android:topLeftRadius="6dp"
       android:bottomRightRadius="6dp" />
    

    第二个drawable也是如此。

    您必须将这些已编辑(左右颠倒)的可绘制对象放在res/drawable-v12 文件夹中。如果它不存在,请创建它。您的常规可绘制对象(您在上面发布的)将保留在 red/drawable 文件夹中。

    Bug 提交于:Link

    【讨论】:

    • 我正在做,但仍然没有结果。
    • @El_Mochiq 你能发布你更新的 xml 代码吗?我也觉得只需要切换bottom_X_Radius,top的不受bug影响。
    • 我阅读了您发布的链接中的讨论,现在可以正常使用了,谢谢!
    【解决方案2】:

    如果您将两个文本视图都放在一个 LinearLayout 中,并在内部 LinearLayout 上设置角半径会发生什么?

    澄清一下:

    <LinearLayout ...>
        <LinearLayout
            android:topLeftRadius="6dp"
            android:topRightRadius="6dp"
            android:bottomLeftRadius="6dp"
            android:bottomRightRadius="6dp"
            ... >
    
            <TextView ... />
            <TextView ... />
    
        </LinearLayout>
    </LinearLayout>
    

    【讨论】:

    • 由于 Layout 正在包裹内容,因此 textviews 的边缘正在显示并且边框没有显示为圆形。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-20
    • 1970-01-01
    相关资源
    最近更新 更多