Android:关于大小/分辨率独立应用程序的问题?

时间:2011-05-04 12:59:51

标签: android layout user-interface screen

我提前道歉提出这个问题,我知道类似的问题已被问过几百次,但尽管我多次阅读Android Screen Support指南,但我仍然不明白如何创建基本布局,适合多个屏幕,无法使用比例尺寸。

所以基本上,如果我总结一下本指南告诉我们要做的事情:

  • 我们应该为您希望应用与之兼容的设备的每个“尺寸组”和“密度组”创建多个布局资源。
  • 我们应该使用RelativeLayoutFrameLayout代替AbsoluteLayout
  • 我们应该使用dp尺寸而不是px尺寸来消除密度差异问题。

确定。这是有道理的。

现在,这是我的问题(我提前为他们的愚蠢道歉):

  • 如果我使用density groups尺寸,为什么必须为不同的Density Independent Pixels (dp)创建不同的布局资源?
  • 我认为为不同的屏幕尺寸设置不同的资源集合,你可能希望你的应用程序布局在小型和大型设备上看起来不同,而不是具有不同尺寸的完全相同的布局,是否正确?所以基本上它意味着如果我只想要一个在所有设备上看起来完全相同的应用程序(只是缩小/扩展以适应屏幕大小),我只需要定义一组资源,对吗?
  • 如果我想创建一个非常简单的布局,它只包含两个按钮,每个按钮占据屏幕宽度的50%,我如何只使用dp尺寸来做到这一点?

谢谢你,再次抱歉再次讨论这个话题......

1 个答案:

答案 0 :(得分:1)

您不必创建不同的布局。我大多只使用一种布局用于纵向,一种用于横向模式,将其他所有内容留给系统。

如果您想获得相同尺寸的2个按钮,请使用

android:layout_width="fill_parent"
android:layout_weight="1"

两个按钮并将它们放入线性布局容器中。

编辑(完整代码,将并排提供两个按钮):

<LinearLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:orientation="horizontal">
    <Button 
        android:layout_width="fill_parent" android:layout_height="wrap_content" 
        android:layout_weight="1"
        android:text="@string/b1" android:onClick="btn1" />
    <Button 
        android:layout_width="fill_parent" android:layout_height="wrap_content" 
        android:layout_weight="1"
        android:text="@string/b2" android:onClick="btn2" />
</LinearLayout>