Android 绝对布局在某些手机上看起来不错,但在其他手机上却不然?
我为 Android 制作了一个计算器应用程序,并使用绝对布局来定位按钮和文本视图。它在我父亲的 HTC Hero 上看起来不错,但当我把它放在我的 EVO 上时,所有内容都被压缩到左上角。我认为这是因为我的屏幕分辨率比我父亲的大,所以我在绝对布局中使用的像素测量在我的手机上无法像在我父亲上那样正确缩放,因为他的像素较少。
我认为如果我使用不同的布局(例如线性布局),它将在不同分辨率的所有手机上正确缩放。我可以使用什么布局以及如何将按钮放置在我想要的位置?使用线性布局,所有东西都堆叠在一起,我不知道如何将东西并排放置,就像计算器应用程序上的按钮一样。绝对布局是我唯一能想到的方式。有人可以给我举个例子或者向我展示你制作的计算器应用程序的布局,以便我看看你是如何做到的吗?
I made a calculator app for Android and used an Absolute layout to position the buttons and textview. It looks good on my dad's HTC Hero, but when I put it on my EVO everything is compressed to the upper left. I think it's because my screen resolution is bigger than my dad's, so the pixel measurements I use in my absolute layout do not scale correctly on my phone like it does on my dads because he has fewer pixels.
I think if I use a different layout like linear layout it will scale correctly on all phones of different resolutions. What layout can I use and how can I position the buttons where I want with it? With linear layout everything just stacks on top of each other and I cant figure out how to put things side by side and all over like buttons on a calculator app should be. Absolute layout was the only way I could think. Can someone maybe give me an example or show me a layout of a calculator app you made so I can see how you did it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不推荐使用
AbsoluteLayout
。要并排放置元素,可以将
LinearLayout
与orientation="horizontal"
结合使用。要处理缩放,请尝试使用
layout_weight
参数。即,如果您想并排创建一个两个按钮,占据整个宽度的空间,并且每个按钮占总宽度的一半,您可以执行以下操作另外,请考虑使用
RelativeLayout
,您可以在其中放置每个元素相对于先前放置的元素。AbsoluteLayout
is not recommended.To place elements side-by-side you can use
LinearLayout
withorientation="horizontal"
.To deal with scaling try to use
layout_weight
parameter. I.e. if you want to create a two button side-by-side taking a full space in width, and each button half of a total width you can do the followingAlso, consider using
RelativeLayout
where you can place each element relative to previously placed ones.停止使用绝对布局!!!!
首选相对或嵌套线性布局来处理情况。
仅当特定设备确实需要时才使用绝对布局,除非不使用它。
谢谢,
STOP USING ABSOLUTE LAYOUT!!!!!
Prefer Relative or Nested Linear Layout to handle situation.
Use absolute layout only when its exactly required on a specific devices, until and unless don't go for it.
Thanks,