Android activity with multiple repeating backgrounds

I am still new to android and I am having trouble creating a layout with two backgrounds that alternate in the x but not the y direction.

I scoffed at what I am trying to create here ...

http://img153.imageshack.us/img153/6008/cnbackground.png

So the top repeats horizontally, then there is a flat roll section in the middle where I will center my content, and then the grass repeats horizontally at the bottom.

Has anyone tried to do something like this before?

John

+2


a source to share


2 answers


Here's a good simple tutorial on the part about re-background image:

http://androidblogger.blogspot.com/2009/01/how-to-have-tiled-background-cont.html



In terms of layout, I would include RelativeLayout as the main parent layout, and then you have three sub layouts to represent the top, middle and bottom. Use android: layout_alignParentTop in the top layout, android: layout_alignParentBottom at the bottom, and the middle content layout should have android: layout_above and android: layout_below attributes set to bottom and top-bottom and bottom (respectively).

+7


a source


You can simulate repeat-x using a layer list as drawable. You draw a bitmap of both x and y and then use a solid offset shape to fill in the repeating y images. Not perfect, but will do the job.



<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
 <item>
  <bitmap
        android:src="@drawable/icon"
        android:tileMode="repeat" />
 </item>
 <item android:top="60dp">
  <shape >
   <solid android:color="#FF000000" />
  </shape>
 </item>
</layer-list>

      

0


a source







All Articles