2010-09-08 16 views

回答

2

如果你想 「補」 的ImageView的:

android:scaleType="fitXY" 

如果你想 「平鋪」 看看BitmapDrawablesetTileModeXY()

+0

如何與多相同的繪製文件不會改變它的大小 – landry 2010-09-08 03:01:34

+0

你嘗試BitmapDrawable,setTileMode填充ImageView的?我沒有親自做過,但對BitmapDrawable的描述是「可繪製的包裝位圖,可以平鋪,拉伸或對齊。」 – 2010-09-08 03:41:32

+0

我只是把drawable放在背景中,它適用於我。謝謝。 – landry 2010-09-09 08:10:02

1

您可以使用下面的代碼片段:

BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),BitmapFactory.decodeResource(getResources(), R.drawable.tile_image)); 
bitmapDrawable.setTileModeX(TileMode.REPEAT); 
imageView.setImageDrawable(bitmapDrawable); 

此示例使用tile_image填充imageView並在X方向重複它。您可以在Y方向或兩者使用其他方法來瓦:

bitmapDrawable.setTileModeY(TileMode.REPEAT); 
bitmapDrawable.setTileModeXY(TileMode.REPEAT,TileMode.REPEAT); 
0

在res文件夾中創建一個可繪製,將其命名爲tile_drawable.xml

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

使用此繪製爲背景,爲您的ImageView,完成!

<ImageView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:background="@drawable/tile_drawable" /> 

這是通過XML來做到這一點