简体   繁体   English

如何在Android中将屏幕分为两部分?

[英]How to Split the Screen into two parts in Android?

I'm trying to put 1 Button and 1 listviews into my layout. 我试图将1 Button和1 listviews放入我的布局。 The problem is that . 问题是。 The first Button could have a few items (0,to 5) and the second listview could have 1 listviews ,It depends upon on Each Button Click.i Dont Know how to Split the screen? 第一个Button可能有几个项目(0到5),第二个Listview可能有1个列表视图,这取决于每个Button单击。i不知道如何拆分屏幕? My Images, 我的图片, 分屏

Use two LinearLayout having height fill_parent and orientation should be vertical. 使用高度为fill_parent且方向应垂直的两个LinearLayout。 and width should be defined by you depending upon your requirement. 宽度应根据您的要求由您定义。 Hope this may help you. 希望这对您有帮助。

Use android:layout_weight to set the ratio of the elements. 使用android:layout_weight设置元素的比例。

Edit: I attached the basic layout you need, it only contains the splitted UI. 编辑:我附加了您需要的基本布局,它仅包含拆分的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>

When the view creates only the list is visible, after I click one of the list item the screen ratio is set to 1:2. 当视图创建时,只有列表可见,当我单击列表项之一后,屏幕比例设置为1:2。

Here is the xml: 这是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" />

This is the java code to set the ratio of the fragments. 这是设置片段比例的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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM