2012-08-09 86 views
0

我有一個2×2網格中的4個ImageButton(使用TableLayout)的屏幕。在不同的屏幕布局上的ImageButton大小

我需要支持所有不同的屏幕尺寸。所以我創建了4個佈局文件夾(小,中,大和超大)。

它工作正常的ImageButton的位置。但在大屏幕和超大屏幕上,ImageButton的尺寸太小。

我試圖解決這個問題,使用mdpi之間的x0.75,x1,x1.5和x2關係,使用4個文件夾實現diferents密度(drawable-ldpi,drawable-mdpi,drawable-hdpi和drawable-xhdpi)和其他文件夾。

但我認爲這是行不通的或不是解決這個問題的正確方法。

這是正確的解決方法?

我擔心小屏幕,但與高密度。或低密度的中等屏幕。在這些情況下,可能沒有工作,對吧?

我的另一個想法是強制每個尺寸文件夾的每個佈局上ImageButton的大小(以傾斜度測量)。這是一個更好的解決方法?

我真的失去了這個。我想要應用最好的/正確的解決方案。

有人可以幫我嗎?

感謝和抱歉,我英文不好

更新:

這是佈局:

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

    <TableRow 
     android:gravity="center" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:layout_marginTop="60dip" > 

     <ImageButton 
      android:id="@+id/newCard_button" 
      android:layout_margin="10dip"  
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"    
      android:background="@drawable/selector_new_card_button"/> 

     <ImageButton 
      android:id="@+id/showLastTicket_button" 
      android:layout_margin="10dip"  
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"   
      android:background="@drawable/selector_show_last_ticket_button"/> 

    </TableRow> 

    <TableRow 
     android:gravity="center"   
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent"> 

     <ImageButton 
      android:id="@+id/cancelLastTransaction_button" 
      android:layout_margin="10dip"  
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"   
      android:background="@drawable/selector_anulla_button"/> 

     <ImageButton 
      android:id="@+id/searchCustomer_button" 
      android:layout_margin="10dip"  
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/selector_search_customer_button"/> 

    </TableRow> 
</TableLayout> 
+0

你可以發佈你的XML佈局代碼? – iTurki 2012-08-09 18:40:19

回答

0

您可以嘗試調整ImageButton的佈局寬度和高度值,方法是給出精確的值,例如50dip而不是換行內容。傾角值將在不同屏幕中以不同尺寸出現,因爲傾角指的是密度獨立像素。

+0

我終於做到了。我不推測這是最好的方式,但它有效。謝謝! – 2012-08-15 12:52:05

1

好了,所以我會建議這是使用較新限定符sw600dpsw720dp(最短寬度:600dp或720dp)爲這些屏幕定義更大的尺寸 - 基本上是7「和10」平板電腦。您可以定義特定的dimen變量,並在values-sw600dp資源文件夾中具有較大的值,或者實際上在layout-sw600dp資源文件夾中完全創建不同的佈局,具體取決於需要更改多少。

相關問題