Android xml layer-list 在某些设备上未正确显示 [英] Android xml layer-list not displayed correctly on some devices
问题描述
我有一个可绘制的 xml 图层列表作为视图的背景,但在某些设备上无法正确显示.
I have an xml layer list drawable as a background for view, which is not displayed correctl on some devices.
我有一个 4.2.2 的华为 Ascend Mate,显示正常.在 4.1.2 的华硕 phonepad 平板电脑上,我只看到项目形状的笔划,而没有看到其他项目.
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.
我做错了什么?
<?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>
推荐答案
我已经解决了这个问题.显然在某些设备(android 4.0 和 4.1.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>
所以千万不要留下没有颜色的有边框的形状,因为有些设备会将它涂成黑色!
这篇关于Android xml layer-list 在某些设备上未正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!