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.
How to fit image without stretching and maintain aspect ratio? Answer: If you want to use the image as a CSS background, there is an elegant solution. Simply use cover or contain in the background-size CSS3 property. contain will give you a scaled-down image.
The background-repeat CSS property sets how background images are repeated. A background image can be repeated along the horizontal and vertical axes, or not repeated at all.
To control the repetition of an image in the background, use the background-repeat property. You can use no-repeat value for the background-repeat property if you do not want to repeat an image, in this case, the image will display only once.
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>
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