How to repeat the background image horizontally only on Android?

Asked 2 years ago, Updated 2 years ago, 161 views

To view Android image resources repeatedly

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

This is how you define it in XML and set it to BitmapDrawable in View, etc.

However, with this method, it will appear repeatedly in both horizontal and vertical directions.

How do I avoid repeating horizontally and vertically?

android bitmap

2022-09-29 20:28

1 Answers

BitmapDrawabledraw=(BitmapDrawable)getResources().getDrawable(R.drawable.draw);
draw.setTileModeX (Shader.TileMode.REPEAT);

https://stackoverflow.com/questions/11934845/android-tilemode-x-or-y-only
Excerpt from

Note:
There was a much easier way.

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

Enter a description of the image here


2022-09-29 20:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.