有时候,我们的设计需要在一个布局文件中重复的使用某个图片,作为一个布局区域的背景图。
如何实现呢?
可以通过android:tileMode="repeat" 属性来达到,具体做法是:
1、在drawable文件夹下创建一个资源文件repeat_bg.xml,里面的android:src属性设置成要重复展示的图片。
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/firstpage_zx_bg"
android:tileMode="repeat" />
2、在所需要展示的布局,设置其background属性为repeat_bg 就可以达到效果了:
<LinearLayout
android:id="@+id/layout_topbase"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/repeat_bg"
android:orientation="horizontal">
</LinearLayout>
感兴趣的同学,可以深入研究下android:tileMode属性,看看其原理。也欢迎同学们推荐其它可以实现相同效果的方法。