【问题标题】:How to Split the Screen into two parts in Android?如何在Android中将屏幕分成两部分?
【发布时间】:2011-09-06 06:17:11
【问题描述】:

我正在尝试将 1 个按钮和 1 个列表视图放入我的布局中。问题是。第一个按钮可能有几个项目(0 到 5),第二个列表视图可能有 1 个列表视图,这取决于每个按钮单击。我不知道如何拆分屏幕? 我的图片,

【问题讨论】:

  • 你能发一张照片是什么样子的吗?
  • 嗨,我更新了我的答案,你可以使用基本布局,它将屏幕分割为 1:2 比例。

标签: java android split


【解决方案1】:

使用两个具有高度 fill_parent 和方向的 LinearLayout 应该是垂直的。和宽度应由您根据您的要求定义。希望这对您有所帮助。

【讨论】:

    【解决方案2】:

    使用 android:layout_weight 设置元素的比例。

    编辑:我附上了您需要的基本布局,它只包含拆分的 UI。

     <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
        <TableLayout 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content" 
            android:id="@+id/tableLayout1"
            android:layout_weight="2" >
            <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
                <TextView android:text="Mobilizitaion" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
                <Spinner android:id="@+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
            </TableRow>
            <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content">
                <TextView android:text="Main" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
                <Spinner android:id="@+id/spinner2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
            </TableRow>
            <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content">
                <TextView android:text="Services" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
                <Spinner android:id="@+id/spinner3" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
            </TableRow>
            <TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content">
                <TextView android:text="Etc" android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
                <Spinner android:id="@+id/spinner4" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
            </TableRow>
        </TableLayout>
        <LinearLayout
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_weight="1" >
        </LinearLayout>
    </LinearLayout>
    

    当视图创建时只有列表是可见的,当我单击其中一个列表项后,屏幕比例设置为 1:2。

    这里是xml:

    <FrameLayout
                android:id="@+id/fragment_list"
                android:layout_weight="0"
                android:layout_width="fill_parent"
                android:layout_height="match_parent" />  
        <FrameLayout 
            android:id="@+id/framelayout_for_right_fragment"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_weight="0" />
    

    这是设置片段比例的java代码。

    final FrameLayout leftFragment = (FrameLayout) findViewById(R.id.fragment_list);
            leftFragment.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 2));
            final FrameLayout rightFragment = (FrameLayout) findViewById(R.id.framelayout_for_right_fragment);
            rightFragment.setAnimation(AnimationHelper.inFromRight());
            rightFragment.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1));
    

    【讨论】:

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