2016-01-17 88 views
-2

嗨,在我的應用程序中有6個按鈕,每個都有背景圖像,問題是圖像在設置爲背景時模糊。我試過所有尺寸,但問題保持不變我也嘗試將它設置爲ImageView,Button和ImageButton。當設置爲按鈕的背景時,圖像變得模糊,ImageButton

如果我設置爲背景,應該是圖像的大小。

這裏是我的XML,這是它的樣子.. http://imgur.com/DhHamds

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<include 
    android:id="@+id/tool_bar" 
    layout="@layout/tool_bar" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent"/> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:orientation="horizontal" 
     android:layout_weight="1"> 

     <ImageButton 
      android:id="@+id/cstatn" 
      android:layout_width="0dp" 
      android:scaleType="fitXY" 
      android:layout_height="match_parent" 
      android:layout_weight="1"/> 

     <ImageButton 
      android:id="@+id/cclinic" 
      android:layout_width="0dp" 
      android:scaleType="fitXY" 
      android:layout_height="match_parent" 
      android:layout_weight="1"/> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dip" 
     android:orientation="horizontal" 
     android:layout_weight="1" > 

     <ImageButton 
      android:layout_width="0dip" 
      android:layout_height="match_parent" 
      android:layout_weight="1" /> 

     <ImageButton 
      android:layout_width="0dip" 
      android:layout_height="match_parent" 
      android:layout_weight="1"/> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dip" 
     android:orientation="horizontal" 
     android:layout_weight="1" > 

     <ImageButton 
      android:layout_width="0dip" 
      android:layout_height="match_parent" 
      android:layout_weight="1" /> 

     <ImageButton 
      android:layout_width="0dip" 
      android:layout_height="match_parent" 
      android:layout_weight="1" /> 
    </LinearLayout> 
</LinearLayout> 

回答

0

圖像被拉伸,因爲你的按鈕的大小從圖像的大小不同。要使用圖像作爲背景而不拉伸,請將圖像轉換爲9patch文件。在互聯網上有很多信息可以解釋它可以如何使用,如this one

+0

所以如果我使用9補丁的圖像,它不會伸展?根據我的代碼應該是圖像的大小? – Sunil

+0

9張圖片仍然會被拉伸,但它們會根據您的設計進行拉伸。圖像的大小取決於圖像的內容和按鈕的大小,圖像應該明顯小於按鈕。 – Kai

+0

這裏在我的上面的代碼我沒有指定任何寬度和高度的按鈕,但是當我試圖爲一個按鈕設置圖像時,其拉伸和圖像應該在所有類型的設備中看起來不錯。 – Sunil

相關問題