Android image background repeat

tinti picture tinti · Feb 14, 2012 · Viewed 26.5k times · Source

I have a image used for a LinearLayout background Let's say image has 20x100 px I want to make the image repeat only on x axes ... something like this in css

background-repeat:repeat-x;

The LinearLayout is kinda big (1024 x 680 px) so my image will cover the entire width but only in the top (the rest of 580 px of height will be transparent) I hope i was clear Thanks

Answer

Zeba picture Zeba · Jun 7, 2012

try using android:tileMode

create background.xml in drawable folder as:

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

and then use it in your layout xml as:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:orientation="vertical" >