tags:

views:

359

answers:

1

Hi,

I'm still new to android and i'm having trouble creating a layout with two backgrounds that tile in the x direction but not y.

I've mocked up what I'm trying to create here...

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

So the top section repeats horizontally, then there's a flat creen section in the middle in which I will center my content, then there's some horizontally repeating grass along the bottom.

Has anyone tried to do anything like this before?

Jon

+1  A: 

Here's a good simple tutorial on the repeated background image part:

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

As far as the layout, I'd go with a RelativeLayout as my main parent layout, and then you'll have three sub-layouts to represent the top, middle, and bottom sections. Use android:layout_alignParentTop on the top layout, android:layout_alignParentBottom on the bottom, and the middle content layout should have the attributes android:layout_above and android:layout_below set to the @+id's of the bottom and top (respectively).

Rich
I had hoped to be able to just add 2 backgrounds to the main activity, without having to actually divide the screen into 3 but I'm guessing you can only have one android:background attribute on a tag. Also, that article only mentions 3 tileModes repeat, mirror, or clamp and doesn't say how to get something to tile only horizontally. In css I would do this by setting {background-repeat:repeat-x;}
jonhobbs
Yep...but this ain't html/css, so you have to hack around the things you would expect to be there that aren't. Since you can't do it via repeat-x, I would make the top/bottom layouts have a layout_height of wrap_content, and give them a child ImageView instead of a background. The ImageView's src can be your @drawable that uses the bitmap element with tileMode = repeat. That way, everything stays dynamically sized anyway (which is clearly the intention of the Android gods)
Rich