Android之背景图片设置为重复而不是默认的拉伸

来源:互联网 发布:app数据统计模板 编辑:程序博客网 时间:2024/05/01 12:20



以LinearLayout为例,它提供的background属性将会将背景图片拉伸,相当难看。事实上我们只需做少量的修改就可以实现web编程中css背景图片的效果。来试试吧。

创建重复的背景图片

在drawable目录下创建一个repeat_bg.xml:  src是引用图片的名称

<?xml version="1.0" encoding="utf-8"?><bitmap xmlns:android="http://schemas.android.com/apk/res/android"    android:src="@drawable/manual_bg"    android:tileMode="repeat" />

然后在布局的xml文件中可以这样引用:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@drawable/repeat_bg"></LinearLayoutt>




以LinearLayout为例,它提供的background属性将会将背景图片拉伸,相当难看。事实上我们只需做少量的修改就可以实现web编程中css背景图片的效果。来试试吧。