Android:关于与大小/分辨率无关的应用程序的问题吗?
我提前为问这个问题表示歉意,我知道类似的问题已经被问过数百次,但尽管我阅读了 Android 屏幕支持 指南多次,我仍然不明白如何创建适合多个屏幕的基本布局,而无法使用比例尺寸。
所以基本上,如果我总结一下本指南告诉我们要做的事情:
- 我们应该为您希望应用程序兼容的设备的每个“尺寸组”和“密度组”创建多个布局资源。
- 我们应该使用
RelativeLayout
或FrameLayout
而不是AbsoluteLayout
- 我们应该使用
dp
尺寸而不是px 尺寸来摆脱密度差异问题。
好的。这是有道理的。
现在,这是我的问题(我提前为他们的愚蠢表示歉意):
- 如果我使用
密度独立像素(dp)
,为什么我必须为不同的密度组
创建不同的布局资源代码> 尺寸? - 我认为为不同的屏幕尺寸提供不同的资源集的目的是,您可能希望您的应用程序布局在小型和大型设备上看起来不同,而不是具有不同尺寸的完全相同的布局,对吗?所以基本上这意味着,如果我只想要一个在所有设备上看起来完全相同的应用程序(只是缩小/扩展以适应屏幕尺寸),我只需要定义一组资源,对吗?
- 如果我想创建一个非常简单的布局,仅包含两个按钮,其中每个按钮占据屏幕宽度的 50%,如何仅使用
dp
尺寸来做到这一点?
谢谢您,再次抱歉再次讨论这个话题......
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.
So basically, if I sum-up what this guide tells us to do:
- We should create several layout resources for each "size group" and "density group" of devices you want your app to be compatible with.
- We should use
RelativeLayout
orFrameLayout
instead ofAbsoluteLayout
- We should use
dp
dimensions instead ofpx
dimensions to get rid of the density difference problem.
Ok. This makes sense.
Now, here are my questions (I apologize in advance for their silliness):
- Why do I have to create different layout resources for different
density groups
if I useDensity Independent Pixels (dp)
dimensions? - I suppose that the point of having different sets of resources for different screen sizes is that you might want your application layout to look different on a small and a large device, not to have the exact same layout with different dimensions, correct? So basically it means that if I just want an application that looks exactly the same on all devices (just shrinking/expanding to fit the screen size), I only have to define one set of resources, correct?
- If I want to create a really simple layout, that just contains two buttons, where each buttons take 50% of the screen's width, how do I do that by just using
dp
dimensions?
Thank you, and sorry again for going over this topic again...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不必创建不同的布局。我大多只使用一种布局用于纵向模式,另一种布局用于横向模式,将其他一切留给系统。
如果您想获得 2 个相同大小的按钮,只需使用
这两个按钮并将它们放入线性布局容器中。
编辑(完整代码,将并排给出两个按钮):
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
for both buttons and put them into a linear layout container.
edit (complete code, will give two buttons side by side):