image background - how to repeat image as background rather than stretch it

lior picture lior · Jan 12, 2011 · Viewed 14.7k times · Source

I have an image I want to use as a background to some layout. the problem is the image contains a texture of slant lines, so if i use a 1 pixel width image or a 9 patch the image is stretched and the texture is Twitching, so i can see the slant lines as latitude lines. I saw that he android emulator uses a similar texture in the progress bar indeterminate animation, is there a special/simple definition to order the background image to repeat itself rather than stretch? is there a way to do it with 9 patch, cause eventualy i also need the corners to be round. thanks for the help.

Answer

Subin Sebastian picture Subin Sebastian · Feb 6, 2012

You would probably want to take a look at tile mode as Xandy answered. Here is some code for your reference which is used by me.

repeat.xml

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

main.xml

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