Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Make a portion of an image repeatable in android?

I wish to achieve something similar to the following: enter image description here

Notice how the image pattern to the right of the triangle repeats until it hits the edge of the screen. Also, the triangle will not actually be a triangle (i.e. the image will not be a simple shape) so please be aware of that. I'm quite new to Android and know that in iOS it is possible to set a portion of the image to repeat. I'm not sure if this is true also of android and if so how? If not, then what would be the recommended approach?

like image 443
TomTaila Avatar asked Oct 29 '14 13:10

TomTaila


1 Answers

To repeat an image you may set the TileMode for this Bitmap. To move it in your case to the right you may define a layer-list drawable and give its item a left property:

tile_background.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <bitmap android:src="@drawable/tile_start" android:gravity="left|bottom"/>
    </item>
    <item android:left="60px">
        <bitmap android:src="@drawable/tile" android:tileMode="repeat"/>
    </item>

</layer-list>

just some layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <View
        android:id="@+id/view1"
        android:layout_width="wrap_content"
        android:layout_height="26dp"
        android:background="@drawable/tiled_background" />

</LinearLayout>

enter image description here

like image 149
blender Avatar answered Sep 27 '22 17:09

blender