【问题标题】:Eclipse Layout: How to support multiple screen sizes in landscape mode?Eclipse Layout:如何在横向模式下支持多种屏幕尺寸?
【发布时间】:2015-08-31 23:56:16
【问题描述】:

如果我想支持多种屏幕尺寸,我会使用 small、normal、large 和 xlarge 尺寸。这在纵向模式中效果很好,但在横向模式中却不行。例如,如果我在横向模式中为 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" />

【问题讨论】:

    标签: android eclipse layout landscape


    【解决方案1】:

    为了支持多屏幕,您必须在活动中添加片段。你做了简单的编程。你需要实现 Fragments。

    为此,请访问并试用教程

    http://developer.android.com/guide/components/fragments.html

    https://developer.android.com/training/basics/fragments/index.html

    在这里您可以找到 Fragments 的示例。

    一切顺利。

    【讨论】:

      【解决方案2】:

      我通过捕获运行时窗口的高度和宽度大小来做到这一点 建议如何在没有任何复杂性的情况下做到这一点 1. 使用Relative layout,维护reference 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);
      }
      

      【讨论】:

        猜你喜欢
        • 2015-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-21
        相关资源
        最近更新 更多