2012-02-16 50 views
0

我有一個佈局,具有六個按鈕。它們全都具有72x72dip的尺寸,所以它們在小屏幕上看起來更大,反之亦然。拉伸相對於屏幕尺寸的圖像

我該如何解決這個問題?我希望按鈕的大小相同(例如屏幕寬度的10%),但我不知道如何去做。

這是我的佈局的外觀:

enter image description here

佈局的源代碼可以發現here

+0

請只張貼的代碼有問題;沒有人會挖掘它找到罪魁禍首;) – Adrian 2012-02-16 14:57:18

+0

我已經做到了。發佈的代碼僅用於按鈕。另外問題不是關於這個特定的代碼,而是一個通用的解決方案。 – Force 2012-02-16 15:02:37

回答

0

1 - 您是否修復了所有'圖像視圖'至layout_width &高度72dip? 2 - 通常72dip是在每一個屏幕大小同樣的事情......但是你還是可以有3個(或4,如果你支持XHDPI)分辨率圖片的...

2 - 小別勝新婚添加4種不同的你繪製對象:

2.1抽拉

2.2抽拉-LDPI

2.3抽拉-MDPI

2.4抽拉-HDPI

考慮以下比例爲您的圖像: LDPI是3 MDPI是4 華電國際是6

因此,請務必先華電國際的圖像,因此您可以isealy調整應用比1.5和2個其他圖像(只是除以2例如LDPI)。

3.順便說一句,你爲什麼只是自己做了這一切?似乎你在Android 4.0,爲什麼你不使用Android的新「DashBoard」類?

+0

是的,我已經爲不同的屏幕尺寸有不同的圖像尺寸,但它們都是72x72dip。 – Force 2012-02-16 15:04:47

0

我通常通過將寬度和高度設置爲wrap_content,然後調整ImageButton窗口小部件上的layout_weight,以便每個按鈕佔用相同數量的空間。我通常做scaleType="center_inside",使他們很好地排隊。然後根據需要使用邊距來填充TableView的邊緣。

0

幾點快速觀察:

a。您不需要TableLayout,只需使用LinearLayout

b。你不需要單獨的ImageView和TextView,你可以使用Button和圖像來使用它

android:drawableTop="@drawable/" 

c。切勿在任何視圖的寬度/高度中使用絕對值,因此請使用wrap_content。

樣品佈局應該是這樣的:

<LinearLayout 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:orientation="vertical"> 

<!-- Row 1 --> 
<LinearLayout 
    android:layout_height="0dp" 
    android:layout_width="fill_parent" 
    android:layout_weight="1.0" 
    android:orientation="horizontal"> 

<Button 
    android:layout_height="wrap_content" 
    android:layout_width="0" 
    android:layout_weight="1.0" 
    android:text="Preferences" 
    android:drawableTop="@drawable/Preferences" /> 

<Button 
    android:layout_height="wrap_content" 
    android:layout_width="0" 
    android:layout_weight="1.0" 
    android:text="Preferences" 
    android:drawableTop="@drawable/Preferences" /> 

</LinearLayout> 

    . 
    . 
    . 
</LinearLayout> 


</LinearLayout> 
+0

非常感謝您的改進! **(a)**我嘗試過,但我無法實現。 **(b)**我更喜歡使用這種方法,因爲它不是一個按鈕,而是一個可點擊的佈局(所以點擊時它有一個很好的顏色變化)**(c)**在發佈問題之前,我確實使用' wrap_content',但顯然我忘了在發佈代碼之前將其改回。 – Force 2012-02-16 15:09:01

+0

檢查我的答案如何使用LinearLayout .. – PravinCG 2012-02-16 15:14:36

+0

完美的作品!非常感謝您的回答:) – Force 2012-02-16 15:26:16