Axarydax
Axarydax

Reputation: 16603

Android tiled image with beginning and end

I'd like to do something like this:

enter image description here

The closest I got was with a layer list, which aligns the left image to the left, the right to the right, and sets the center image to repeat itself.

<layer-list  xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <bitmap android:src="@drawable/left"
            android:gravity="left"/>
    </item>
    <item android:left="16dp" android:right="16dp">
        <bitmap android:src="@drawable/center"
            android:tileMode="repeat"/>
    </item>
    <item>
        <bitmap android:src="@drawable/right"
            android:gravity="right"/>
    </item>
</layer-list>

The problem is, that the pattern doesn't know it has to repeat only "complete" iterations of center image, so on some screens it looks like this:

enter image description here

Because Android just repeats the center image for example 4.5 times and it doesn't properly join with the right one.

Is it possible to do this without implementing this functionality as a custom View, where I'd calculate and render the image?

Upvotes: 0

Views: 64

Answers (1)

Ridcully
Ridcully

Reputation: 23665

If the image is actually that simple as in your example. may be the best way would be to implement your own Drawable and paint the image in the draw() method.

Don't worry, this in relatively simple and probably the only way anyways to achieve what you want.

Upvotes: 1

Related Questions