Shape XML Drawable无法解析为Bitmap XML Drawable

时间:2011-12-19 09:54:09

标签: android android-layout drawable

我使用形状XML drawable作为LinearLayout的背景。

文件:background.xml

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

    <gradient
        android:angle="270"
        android:endColor="@color/bg_end_blue"
        android:startColor="@color/bg_start_blue" />

    <corners android:radius="0dp" />

</shape>

然后我读到了关于抖动以及如何改善这种背景的外观(通过这篇文章http://android.amberfog.com/?p=247),因此我创建了这个位图XML drawable:

文件:background_bitmap.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:src="@drawable/background"
    android:tileMode="repeat" />

并尝试将其应用于LinearLayout。但我得到了:

org.xmlpull.v1.XmlPullParserException: Binary XML file line #5: <bitmap> requires a valid src attribute

你知道我做错了什么吗?在此先感谢!!

1 个答案:

答案 0 :(得分:1)

问题是您正在尝试将可绘制的xml文件作为位图加载到background_bitmap.xml中。需要一个图像作为其src,另一个xml文件将无法工作,据我所知 以前有关于将抖动应用于渐变的问题,这里有一个:Is it possible to dither a gradient drawable?