2011-06-13 59 views
0

我想在我創建的佈局中沿x方向有平鋪背景。我已經按照在線發現的一些很好的說明來正確拼貼,但源圖像現在垂直伸展很好。我認爲這與位圖文件類型的性質有關。Android平鋪背景圖片:使用位圖調整圖片大小?

例圖片:

enter image description here

第一圖像是平鋪之前的背景圖像。第二張圖片是在平鋪之後。正如你所看到的,圖像垂直伸展很好,並且由於調整大小,圖像也顯得有些模糊。

我試過把圖像放在drawable-hdpi和drawable文件夾中。我已經嘗試將XML文件放在兩個文件夾中。這似乎沒有關係。

下面是產生這些兩個圖像的佈局的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical"> 
<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dip" 
    android:background="@drawable/bg" /> 
<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dip" 
    android:background="@drawable/bg_repeat" /> 
</LinearLayout> 

「@繪製/ BG」是實際的圖像本身,bg.png。 「@ drawable/bg_repeat」是以下位圖XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<bitmap 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:src="@drawable/cdetail_bg_unclaimed_details" 
android:antialias="false" 
android:dither="false" 
android:filter="false" 
android:gravity="center|center_vertical" 
android:tileMode="repeat" /> 

對於x-repeat平鋪,是否有替代方案?或者有沒有一些解決方法,我還沒有檢查?我已經更改了抗鋸齒,抖動,濾鏡等所有選項。沒有任何東西可以改變。

感謝您的幫助!

編輯:這似乎是一個使用圖形佈局工具的錯誤。它在我的手機上看起來不錯。

回答

0

這似乎是一個使用圖形佈局工具的錯誤。它在我的手機上看起來不錯。

0

您不能使用xml單向重複位圖背景,但Java代碼肯定可以做到這一點。

BitmapDrawable bitmap = (BitmapDrawable) getResources().getDrawable(R.drawable.image); 
bitmap.setTileModeX(TileMode.REPEAT); 

所以,現在如果你設置這個「位圖」的任何視圖的背景

例如:如果我們有一個TextView「文本」,然後 text.setBackgroundDrawable(位)將設置該文本的背景 - 將
改爲「位圖」。

將重複x方向,但會保持其高度在y方向

希望這有助於。