Android关于LinearLayout和RelativeLayout背景设置的区别

1.LinearLayout:设置背景时即设置android:background时,假如LayoutLayout设置了android:layout_width="wrap_content"。那么你的布局会和你的图片大小一样大。并不会出现图片失真严重的问题

2.RelativeLayout:设置背景时,即设置了android:background时,假如RelativeLayout设置了android:layout_width="wrap_content"。那么你的布局并不会和你的图片一样大。而是布局填充整个屏幕背景也会跟着填充整个屏幕。这样就造成了图片失真严重。

解决办法:

1.新建一个drawable文件夹,在文件夹中新建一个xml文件,内容如下代码所示:

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

2.在你的布局文件中设置RelativeLayout的背景为android:background=“@drawable/xml文件的名称”

3.到此结束,失真问题搞定。

posted on 2013-09-25 11:55  飘杨......  阅读(4179)  评论(0编辑  收藏  举报