Android 背景图片重复平铺

时间:2023-03-08 23:11:47
Android 背景图片重复平铺

有时候我们需要将一个图片横向或者纵向的平铺(重复循环),这个时候我们需要创建一个xml文件,如下:

<?xml version ="1.0" encoding ="utf-8" ?>
<!-- 背景图片平铺 -->
<bitmap xmlns:android ="http://schemas.android.com/apk/res/android"
android:src ="@drawable/subtitlebg"
android:tileMode="repeat" />
android:src:设置需要重复平铺的图片
android:tileMode:设置图片的平铺方式,有四种方式:

Android 背景图片重复平铺

然后在xml布局文件中引用该文件:

 <ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/subtitlebg_bitmap"
/>

然后运行程序就ok了!