Eclipse Layout:如何在横向模式下支持多种屏幕尺寸?
Eclipse Layout: How to support multiple screen sizes in landscape mode?
如果我想支持多种屏幕尺寸,我会使用小尺寸、普通尺寸、大尺寸和超大尺寸。这在人像模式下效果很好,但在风景模式下却不行。例如,如果我在横向模式中为 3,2" 设备创建布局,则相同的代码不适用于横向模式中的 3,3" 设备。因为它在 3,3" 设备中看起来不对称。我做错了什么?!
正如我所说:我对 3,2" 和 3,3" 设备 (RelativeLayout) 使用相同的代码:
<Button
android:id="@+id/Button01"
android:layout_width="150dp"
android:layout_height="75dp"
android:layout_alignLeft="@+id/button1"
android:layout_alignParentBottom="true"
android:layout_marginBottom="50dp"
android:text="Button" />
<Button
android:id="@+id/Button02"
android:layout_width="150dp"
android:layout_height="75dp"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_marginLeft="25dp"
android:layout_toRightOf="@+id/button1"
android:text="Button" />
<Button
android:id="@+id/Button03"
android:layout_width="150dp"
android:layout_height="75dp"
android:layout_alignBaseline="@+id/Button01"
android:layout_alignBottom="@+id/Button01"
android:layout_alignLeft="@+id/Button02"
android:text="Button" />
<Button
android:id="@+id/button1"
android:layout_width="150dp"
android:layout_height="75dp"
android:layout_above="@+id/Button01"
android:layout_alignParentLeft="true"
android:layout_marginBottom="46dp"
android:layout_marginLeft="78dp"
android:text="Button" />
要支持多屏,您必须在 activity 中添加片段。你做的很简单 programming.You 需要实现 Fragments。
为此请访问本教程并试用教程
http://developer.android.com/guide/components/fragments.html
和
https://developer.android.com/training/basics/fragments/index.html
在这里你可以找到片段的样本。
祝一切顺利。
我是通过捕获运行时 window 高度和宽度大小以及
建议如何在没有任何复杂城市的情况下做到这一点
1.使用相对布局并维护引用id。
2. 明确地将高度或宽度的百分比应用于组件。
示例:
WindowManager wm = (WindowManager) context
.getSystemService(context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
int width = metrics.widthPixels;
int height = metrics.heightPixels;
在Activity句柄UI组件中:
textView.setWidth(getSize(screenWidth, 30));
textView.setHeight(getSize(screenHeight, 13));
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getSize(screenHeight, 6));
public static int getSize(int screenSize, double percentage) {
return (int) ((screenSize * percentage) / 100);
}
如果我想支持多种屏幕尺寸,我会使用小尺寸、普通尺寸、大尺寸和超大尺寸。这在人像模式下效果很好,但在风景模式下却不行。例如,如果我在横向模式中为 3,2" 设备创建布局,则相同的代码不适用于横向模式中的 3,3" 设备。因为它在 3,3" 设备中看起来不对称。我做错了什么?!
正如我所说:我对 3,2" 和 3,3" 设备 (RelativeLayout) 使用相同的代码:
<Button android:id="@+id/Button01" android:layout_width="150dp" android:layout_height="75dp" android:layout_alignLeft="@+id/button1" android:layout_alignParentBottom="true" android:layout_marginBottom="50dp" android:text="Button" /> <Button android:id="@+id/Button02" android:layout_width="150dp" android:layout_height="75dp" android:layout_alignBaseline="@+id/button1" android:layout_alignBottom="@+id/button1" android:layout_marginLeft="25dp" android:layout_toRightOf="@+id/button1" android:text="Button" /> <Button android:id="@+id/Button03" android:layout_width="150dp" android:layout_height="75dp" android:layout_alignBaseline="@+id/Button01" android:layout_alignBottom="@+id/Button01" android:layout_alignLeft="@+id/Button02" android:text="Button" /> <Button android:id="@+id/button1" android:layout_width="150dp" android:layout_height="75dp" android:layout_above="@+id/Button01" android:layout_alignParentLeft="true" android:layout_marginBottom="46dp" android:layout_marginLeft="78dp" android:text="Button" />
要支持多屏,您必须在 activity 中添加片段。你做的很简单 programming.You 需要实现 Fragments。
为此请访问本教程并试用教程
http://developer.android.com/guide/components/fragments.html
和
https://developer.android.com/training/basics/fragments/index.html
在这里你可以找到片段的样本。
祝一切顺利。
我是通过捕获运行时 window 高度和宽度大小以及 建议如何在没有任何复杂城市的情况下做到这一点 1.使用相对布局并维护引用id。 2. 明确地将高度或宽度的百分比应用于组件。 示例:
WindowManager wm = (WindowManager) context
.getSystemService(context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
int width = metrics.widthPixels;
int height = metrics.heightPixels;
在Activity句柄UI组件中:
textView.setWidth(getSize(screenWidth, 30));
textView.setHeight(getSize(screenHeight, 13));
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getSize(screenHeight, 6));
public static int getSize(int screenSize, double percentage) {
return (int) ((screenSize * percentage) / 100);
}