[英]Android: Question about size/resolution independent applications?
I apologize in advance for asking this question, I know similar questions have already been asked hundreds of times, but despite the fact that I read the Android Screen Support guide several times, I still don't understand how to create a basic layout that fits several screen without being able to use proportional dimensions.我提前为提出这个问题道歉,我知道类似的问题已经被问了数百次,但是尽管我多次阅读Android 屏幕支持指南,但我仍然不明白如何创建适合的基本布局几个屏幕无法使用比例尺寸。
So basically, if I sum-up what this guide tells us to do:所以基本上,如果我总结一下本指南告诉我们要做的事情:
RelativeLayout
or FrameLayout
instead of AbsoluteLayout
我们应该使用RelativeLayout
或FrameLayout
而不是AbsoluteLayout
dp
dimensions instead of px
dimensions to get rid of the density difference problem.我们应该使用dp
尺寸而不是px
尺寸来摆脱密度差异问题。Ok.好的。 This makes sense.这是有道理的。
Now, here are my questions (I apologize in advance for their silliness):现在,这是我的问题(我提前为他们的愚蠢道歉):
density groups
if I use Density Independent Pixels (dp)
dimensions?如果我使用与密度无关的Density Independent Pixels (dp)
尺寸,为什么我必须为不同的density groups
创建不同的布局资源?dp
dimensions?如果我想创建一个非常简单的布局,它只包含两个按钮,每个按钮占据屏幕宽度的 50%,我该如何通过仅使用dp
尺寸来做到这一点?Thank you, and sorry again for going over this topic again...谢谢你,再次抱歉再次讨论这个话题......
You do not have to create different layouts.您不必创建不同的布局。 I mostly only use one layout for portrait and one for landscape mode leaving everything else to the system.我大多只使用一种布局用于纵向模式,一种用于横向模式,将其他所有内容留给系统。
If you want to get 2 buttons of the same size just use如果您想获得 2 个相同大小的按钮,只需使用
android:layout_width="fill_parent"
android:layout_weight="1"
for both buttons and put them into a linear layout container.两个按钮并将它们放入线性布局容器中。
edit (complete code, will give two buttons side by side):编辑(完整的代码,将并排给出两个按钮):
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.