开发者

How to Split the Screen into two parts in Android?

开发者 https://www.devze.com 2023-04-02 11:19 出处:网络
I\'m trying to put 1 Button and1 listviews into my layout. 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 Eac

I'm trying to put 1 Button and 1 listviews into my layout. 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? My Images,

How to Split the Screen into two parts in Android?


Use two LinearLayout having height fill_parent and orientation should be vertical. 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.

Edit: I attached the basic layout you need, it only contains the splitted 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.

Here is the 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.

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));
0

精彩评论

暂无评论...
验证码 换一张
取 消