先將圖片放置於 /res/drawable 目錄下,本例放了一張直的 teddy.jpg 和一張 不足螢幕尺寸的小圖片 tile.jpg
 
類型一
 
<???Layout
    ...
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/teddy" >
 
結果如下
當圖片不足螢幕尺寸時,layout 會將照片放大填滿整個螢幕,圖片會失真、糊掉。
 
<???Layout
    ...
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/tile" >
 
先建立一個重複圖片的 main_tile.xml 檔
 
<?xml version="1.0" encoding="utf-8"?>
<bitmap 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/tile"
    android:tileMode="repeat" />
 
然後在 layout 的 background 屬性填入 main_tile.xml
 
<???Layout
    ...
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/main_tile" >
就不會像前一張那樣,圖片的顆粒被放大,呈現出模糊的效果。



沒有留言:
張貼留言