i've used the following code to repeat the image in the background but its not working can any one help?
Layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/grass_bg" >
grass_bg.xml in drawable looks like this
<?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/grass_small" android:tileMode="repeat"/>
its showing the same small image. its not repeating...
To make a background image not repeat in HTML, specify no-repeat in the background-repeat property or the background shorthand property. The background image is set to 'no-repeat' using the 'background-repeat' property.
The background-repeat property sets if/how a background image will be repeated. By default, a background-image is repeated both vertically and horizontally. Tip: The background image is placed according to the background-position property.
Bitmaps (and their states) get reused a lot, and I've found it's easy to lose the tileMode if a BitmapDrawable is used in more than one place. The following code fixes the problem for me:
public static void fixBackgroundRepeat(View view) { Drawable bg = view.getBackground(); if(bg != null) { if(bg instanceof BitmapDrawable) { BitmapDrawable bmp = (BitmapDrawable) bg; bmp.mutate(); // make sure that we aren't sharing state anymore bmp.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT); } } }
Create a copy of grass_bg.xml
for each time you use it (ie grass_bg_2.xml
). This worked for me to assure the tileMode
setting was not lost when the same background is used repeatedly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With