---
title: "背景图平铺"
author: "rayln"
date: "2013-12-05T10:12:49Z"
tags: []
categories: ["移动开发"]
slug: "untitled"
draft: false
lastmod: "2013-12-05T10:12:49Z"
id: 1985520
url: "https://rayln.iteye.com/blog/1985520"
---

以LinearLayout为例，它提供的background属性将会将背景图片拉伸，相当难看。事实上我们只需做少量的修改就可以实现web编程中css背景图片的效果。来试试吧。
创建重复的背景图片
在drawable目录下创建一个repeat_bg.xml:


```java
<?xml version="1.0" encoding="utf-8"?>  
 <bitmap xmlns:android="http://schemas.android.com/apk/res/android"   
android:src="@drawable/bg"   
android:tileMode="repeat" /> 
```
  

然后在布局的xml文件中可以这样引用:


```java
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/repeat_bg"> </LinearLayout>   

```