在Android应用程序中重复背景横幅

dan*_*nny 2 android background repeat

我有一个100像素×100像素的图像,并希望图像保持其比例,但在屏幕上平铺以创建一种横幅.这可能吗?我搜索过谷歌并且只找到了用图像填满整个屏幕的示例.

Cas*_*eyB 7

您可以创建一个xml drawable.在drawable文件夹中创建一个新的xml文件,比如background.xml.然后把它放进去:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
            <bitmap
                android:src="@drawable/backgroundTile"
                android:tileMode="repeat" />
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

然后将其设置为您的背景View.