Android xml layer-list not displayed correctly on some devices

淺唱寂寞╮ 提交于 2019-12-17 19:28:11

问题


I have an xml layer list drawable as a background for view, which is not displayed correctl on some devices.

I have a Huawei Ascend Mate with 4.2.2 which displays it ok. On Asus phonepad tablet with 4.1.2 i see just the item shape stroke and dont see the other items.

What am I doing wrong?

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

    <item>
        <shape android:shape="rectangle" >
            <solid android:color="@color/yellow_color" />
        </shape>
    </item>
    <item>
        <bitmap
            android:gravity="center_horizontal|bottom"
            android:src="@drawable/dotted_bg"
            android:tileMode="repeat" />
    </item>
    <item>
        <shape>
            <stroke
                android:width="4dp"
                android:color="@color/yellow_color" />
        </shape>
    </item>
    <item>
        <bitmap
            android:gravity="center_horizontal|bottom"
            android:src="@drawable/tls_bg" />
    </item>

</layer-list>

回答1:


I've fixed the issue. Apparently on some devices (android 4.0 and 4.1.1) the following code made all layers below the following shape to be overpainted with black color.

<item>
    <shape>
        <stroke
            android:width="4dp"
            android:color="@color/yellow_color" />
    </shape>
</item>

I have added transparent solid color for the shape and now it works fine.

<item>
    <shape>
        <stroke
            android:width="4dp"
            android:color="@color/yellow_color" />
        <solid android:color="@android:color/transparent" />
    </shape>
</item>

So never leave shapes with border without color as some devices will paint it black!




回答2:


The phones use different API levels: 16 & 17. Make sure you don't have several values directories for specific targets (e.g. values-v16 & values-v17).

Also, the items that are not displayed contain references to some drawables, so make sure the files are correct in every drawable directory for each screen dpi.




回答3:


That is probably because the drawable's android:src="@drawable/dotted_bg", android:src="@drawable/dotted_bg" and android:src="@drawable/tls_bg" are too big. Find the screen density of your device and check it's corresponding resource folder (e.g. drawable-xhdpi) and make your drawable's in that folder smaller.



来源:https://stackoverflow.com/questions/26561812/android-xml-layer-list-not-displayed-correctly-on-some-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!