I'm still using in my layout definition the same way to define the background, with a androidbackground parameter, with the path to your repeating background ( actually that was the point : having a consistent way for background, let them be tiled or not )
xml :
<xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/MainLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/backrepeat"
>
...
<LinearLayout
android:id="@+id/MainLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/backrepeat"
>
...
in my drawable directory, I have a back.png file ( the background I want to tile ), and I create this new backrepeat.xml file :
<bitmap android="http://schemas.android.com/apk/res/android"
android:src="@drawable/back"
android:tileMode="repeat" />
Some points :
* I think my first tries failed because I forgot the 'xmlns:android' parameter.
* I tried without the xml version line, and it still works, but I think I will let it be there... Just in case !
* The tilemode can be repeat, mirror, or clamp.
* Although in Java, I could set a different repeat mode for X and Y, I don't think it is possible in the Xml file. Not that I really care for the moment :)
That's all !
Thanks again Romain !
I know it is your job, as a Android engineer, to evangelise and help us, but several times you really helped me, you were quick to answer, with concise and most useful answers...

8 comments:
Lots of syntax errors in your sample code, but thanks for the tip none-the-less.
What syntax errors are you refering to ?
...
Ah, I caught a error in the file name I used.
Are there any other errors ?
Thanks for reporting !
In your description of the bitmap XML file, you have one opening bracket and two closing ones.
Also, where should I put that XML file? Should it go in the drawable directory? The Eclipse plugin seemed to balk at me putting it there; though I can refer to it with the other XML files. Also, I'm getting an XmlPullParserException when I try to load the view saying that the <bitmap> tag "requires a valid src attribute.
I've not ruled out foolishness on my part somewhere since this is my first app.
You were right about the two closing bracket.
I just fixed it. I don't understand where this second bracket come from, as this code comes directly from my game ( Word Prospector ) code.
The second xml is a file from the drawable directory ( I just have :
<?xml version="1.0" encoding="utf-8"?>
as the first line, the rest is what is in the blog entry )
Along with this file, I have the picture file ( back.png ).
Then there is the first xml file, that reference my tiling picture.
This file is my activity description file that is found in the layout directory.
From the error you get, I would say the picture file - back.png- is missing in your drawable directory ?
Hope it helps...
Hello, thanks for getting back to me. The previous error somehow resolved itself.
I have the XML file that contains the single bitmap reference in my drawable directory. I also have the image that I want to tile. If I set the background property of a layout to that image, it displays correctly, but is stretched to fill the screen.
Now, when I set the background property to the bitmap XML file, I get a ResourcesNotFoundException. It says "Could not find the drawable resource matching value {correct ID value from R.java} (resolved name: {correct name}) in current configuration.
That also seems like there's a problem with the file not being around, but nevertheless, when I address it directly, it appears. R.java also finds it and correctly assigns it an ID.
(P.S. You also should probably put the "xmlns:" marker in front of the android declaration in the Bitmap example)
Hum...
Strange...
Are you sure you don't forget to remove the .png extension when refrencing your picture ?
Do you have in your R.java file a value for both your tiled bitmap, and your real bitmap ?
In my case, I have :
public static final class drawable {
public static final int back=0x7f020000;
public static final int backrepeat=0x7f020001;
<...>
I don't really have any more clue...
Quite sure. Because when I add the ".png" it gives me an entirely different error! :-D I tried that as a means of troubleshooting already, and discovered that wasn't the way to go.
R.java does indeed have two entries for each of the bitmaps. Mine happen to be:
public static final int red_dot_wallpaper=0x7f020003;
public static final int repeating_red_dots_background=0x7f020004;
I wondered if it was just a problem with the Eclipse plugin not respecting the full power of the SDK, and so I tried to just load it onto the virtual device. It worked and showed the correct (but scaled) background. The rest of the layout was correct.
I'll keep poking at this and when I find out what's wrong I'll let you know.
For me to get this to work, I had to change :
bitmap android=
from the second XML to
bitmap xmlns:android=
otherwise, I got an error about an unbound prefix.
But, other than that, thanks for the tip!
Post a Comment