在不同的屏幕布局上的ImageButton大小

问题描述:

我有一个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

您可以尝试调整ImageButton的布局宽度和高度值,方法是给出精确的值,例如50dip而不是换行内容。倾角值将在不同屏幕中以不同尺寸出现,因为倾角指的是密度独立像素。

+0

我终于做到了。我不推测这是最好的方式,但它有效。谢谢! – 2012-08-15 12:52:05

好了,所以我会建议这是使用较新限定符sw600dpsw720dp(最短宽度:600dp或720dp)为这些屏幕定义更大的尺寸 - 基本上是7“和10”平板电脑。您可以定义特定的dimen变量,并在values-sw600dp资源文件夹中具有较大的值,或者实际上在layout-sw600dp资源文件夹中完全创建不同的布局,具体取决于需要更改多少。