2014-03-05 99 views
0

我正在编写一款在720p屏幕上运行良好的应用程序。我想让这个应用程序在不同的屏幕尺寸上运行。我读过这篇文章:http://developer.android.com/guide/practices/screens_support.html使用多种布局支持Android中的多种屏幕尺寸

但我很困惑。我为不同的布局制作了3个文件夹(layout-normal,layout-large,layout-xlarge),并在每个文件夹中放置了不同的XML文件。但有一些屏幕布局正常,我的应用程序在其中一些上看起来不错,而在其他一些上看起来很糟糕。例如,这些尺寸是正常的布局:(4.7“WXGA,4”WVGA,3.7“WVGA,...)但我的应用在4”和3.7“上看起来不错,而在其他类型上看起来很不好。活动的main.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:background="@drawable/backasli" 
    android:orientation="vertical" > 

    <TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="100dp" 
     android:paddingTop="140dp" 
     android:stretchColumns="3" > 

     <TableRow 
      android:id="@+id/tableRow6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center" > 

      <TextView 
       android:id="@+id/txt1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:text="pray :" 
       android:textColor="#031a7b" 
       android:textSize="15sp" /> 
     </TableRow> 

     <TableRow 
      android:id="@+id/tableRow1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center" > 

      <TextView 
       android:id="@+id/namaztxt" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:textColor="#031a7b" 
       android:textSize="20sp" /> 
     </TableRow> 

     <TableRow android:gravity="center" > 

      <Button 
       android:id="@+id/buttonchange" 
       android:layout_width="fill_parent" 
       android:layout_height="50dp" 
       android:background="@drawable/ubtn" 
       android:text="change" 
       android:textColor="#ffffff" 
       android:textSize="20sp" /> 
     </TableRow> 
    </TableLayout> 

</LinearLayout> 
+0

我想android:paddingBottom =“100dp” android:paddingTop =“140dp”这会让你的设备对齐问题?在某种意义上它显示的不好? – Lokesh

+0

@Lokesh。究竟!!!这些焊盘会产生问题 – user2855778

+0

然后根据所有布局中的屏幕更改填充。 – Lokesh

回答

2

Android提供了一个很好的方式,以支持多个屏幕尺寸这就是所谓的您应该使用LinearLayout,并检查了你的图形。查看以了解如何调整大小。

Com完全避免:

  1. 计算您的分辨率和屏幕尺寸。你最终会陷入混乱。
  2. 跨dpi的多种布局。

相信我,到目前为止我开发的所有应用程序(12)都已在所有平台上使用带有1个布局文件的权重完成。它工作,并像奇迹般运作。

编辑:

我也从来没有使用比5DP更多的填充和10dp的利润。通过这种方式,我保持代码清洁,Android权重可以保护我的空闲空间。

有关重量的更多信息,请查看this的问题。首先是很好的解释。

再次编辑:

想想吧。您假设dp在所有手机的物理毫米(毫米)方面都是“相同的”。但事实并非如此。实际上X和Y 1 dp可能意味着“mm”中的某些不同。 dp是“不”一致的。使用100dp等代码并设置硬编码的宽度和高度时要小心。更糟糕的是,多个布局文件。你将会遇到很多代码维护的噩梦。

+0

ohk @siddhath :)实际上,我也没有使用硬编码和早些时候我解释,但我没有像我给这个技巧 –

+0

你能解释更多吗?例如,我应该从100dp填充更改为'weight * 100dp'并控制java代码中的权重? – user2855778

+0

好。**重量**是最好的主意......非常感谢。我发现使用这个:[链接](http://www.coderanch.com/t/610485/Android/Mobile/set-size-elements-layout-percent) – user2855778