Image tile in android with ImageView in XML

I try to get the background image for the tile until the background is full.

My current code is:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/cartoonclouds" android:contentDescription="@string/desc" android:tileMode="repeat" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout> </RelativeLayout> 

However, this simply makes the image cover (not tiled) from bottom to top, but NOT from left to right. What should I do?

Edit: Trying an XML Version:

 <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:tileMode="repeat" android:src="@drawable/cartoonclouds" /> 

The main.xml file can find cartoon clubs in the SAME folder as this XML file, but could not find this XML file.

+6
source share
1 answer

First put your image in a file, for example res / drawable / cloud.png. This makes it available to your application as @ drawable / cloud. But this is not a tile (yet).

Next, you must define the bitmap resource (1) with android: tileMode = "repeat". For example, you can define it on mytileablebitmap.xml:

 <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:tileMode="repeat" android:src="@drawable/cloud"/> 

This refers to the original tile image (drawable / cloud) and makes Drawable, which knows how to glue itself to fill the available space.

Then, when you want to use a lined background, use "@ drawable / mytileablebitmap".

(1): http://developer.android.com/guide/topics/resources/drawable-resource.html

+32
source

Source: https://habr.com/ru/post/906222/


All Articles