[英]Android Absolute Layout looks good on some phones but not others?
I made a calculator app for Android and used an Absolute layout to position the buttons and textview. 我为Android开发了一个计算器应用程序,并使用“绝对”布局来放置按钮和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.
在我父亲的HTC Hero上看起来不错,但是当我将其放在EVO上时,所有内容都会压缩到左上方。 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?
有人可以给我一个例子,或告诉我您制作的计算器应用程序的布局,以便我可以看到您如何做的吗?
AbsoluteLayout
is not recommended. 不建议使用
AbsoluteLayout
。
To place elements side-by-side you can use LinearLayout
with orientation="horizontal"
. 要并排放置元素,可以将
LinearLayout
与orientation="horizontal"
。
To deal with scaling try to use layout_weight
parameter. 要处理缩放,请尝试使用
layout_weight
参数。 Ie 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 following 即,如果您要并排创建两个按钮,并在整个宽度上占用整个空间,并且每个按钮占总宽度的一半,则可以执行以下操作
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
Also, consider using RelativeLayout
where you can place each element relative to previously placed ones. 另外,考虑使用
RelativeLayout
,您可以在其中放置每个相对于先前放置的元素的元素。
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, 谢谢,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.