3

I am using a shape XML drawable as a background of a LinearLayout.

File: 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>

Then I read about dithering and how this can improve the look of this background (via this article http://android.amberfog.com/?p=247), thus I created this bitmap XML drawable:

File: 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" />

And tried it to apply to the LinearLayout. But I get a:

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

Do you know what I am doing wrong? Thanks in advance!!

Dimitris Makris
  • 5,183
  • 2
  • 34
  • 54
  • requires a valid src attribute. is that background is valid one?. – Padma Kumar Dec 19 '11 at 09:59
  • Yes it is. I used the initial shape drawable as a background of the layout and it was correct. – Dimitris Makris Dec 19 '11 at 10:02
  • I found this line in that above link. 'Because dithering in Android is applying only for stretchable or tile images. Why? I don’t know. If you know – please write me. I will take a look at the platform code later)'. so try once in ImageView to check its working or not – Padma Kumar Dec 19 '11 at 10:05

1 Answers1

2

The problem is that you are trying to load a drawable xml file as a bitmap in the background_bitmap.xml. needs an image as its src, another xml file won't work as far as I know.
There have been previous questions about applying dither to gradients, here is one: Is it possible to dither a gradient drawable?

Community
  • 1
  • 1
Jave
  • 31,598
  • 14
  • 77
  • 90