【问题标题】:How to split the tablet screen in 2 or three parts in android?如何在android中将平板电脑屏幕分成两部分或三部分?
【发布时间】:2017-07-11 10:26:46
【问题描述】:

我想创建具有下图设计的应用程序。如何创建如图所示的设计。我不知道以这种方式划分平板电脑屏幕。

【问题讨论】:

  • 您可以通过 sumWeight 在 1 个 LinearLayout 中使用 3 个片段。检查这个link

标签: android android-layout android-fragments tablet


【解决方案1】:

如果您想在多种屏幕尺寸上使用您的应用程序,您必须通过fragments

  • 在横向和大屏幕中,您的布局包含 3 个片段:菜单、列表和说明。
  • 在纵向中,您的布局包含 2 个片段,抽屉中的菜单和另一个可以是列表或描述的片段

您可以使用resources 管理这些不同的布局,并使用 FragmentManager 来动态更改列表和描述。

如果您只想要平板电脑,简单的解决方案是将您的视图分成 3 个不带片段的视图,但我不建议使用这种方法,因为您将无法轻松地发展您的应用程序

【讨论】:

    【解决方案2】:

    你为什么不试试这个

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    
    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#ff00"
        />
    
    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#000000"
        />
    
    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#009dff"
        />
    

    在 3 个片段中添加任何内容,然后使用它们替换框架布局。

    getSupportFragmentManager().beginTransaction().replace(R.layout.layout_name, new Fragment_name());
    

    【讨论】:

      【解决方案3】:

      一种简单的方法是同时使用左右抽屉!
      看看下面的链接。

      Reference

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多