我提前道歉提出这个问题,我知道类似的问题已被问过几百次,但尽管我多次阅读Android Screen Support指南,但我仍然不明白如何创建基本布局,适合多个屏幕,无法使用比例尺寸。
所以基本上,如果我总结一下本指南告诉我们要做的事情:
RelativeLayout
或FrameLayout
代替AbsoluteLayout
dp
尺寸而不是px
尺寸来消除密度差异问题。确定。这是有道理的。
现在,这是我的问题(我提前为他们的愚蠢道歉):
density groups
尺寸,为什么必须为不同的Density Independent Pixels (dp)
创建不同的布局资源?dp
尺寸来做到这一点?谢谢你,再次抱歉再次讨论这个话题......
答案 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>