Как разделить экран на две части в Android? - PullRequest
1 голос
/ 06 сентября 2011

Я пытаюсь добавить 1 кнопку и 1 просмотр списка в свой макет. Проблема в том, что . У первой кнопки может быть несколько элементов (от 0 до 5), а у второго списка - 1 список. Это зависит от каждого нажатия кнопки. Мои изображения, SplitScreen

Ответы [ 2 ]

0 голосов
/ 06 сентября 2011

Используйте android: layout_weight, чтобы установить соотношение элементов.

Редактировать: я прикрепил базовый макет, который вам нужен, он содержит только разделенный пользовательский интерфейс.

 <?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));
0 голосов
/ 06 сентября 2011

Используйте два LinearLayout с высотой fill_parent и ориентация должна быть вертикальной.и ширина должна быть определена вами в зависимости от ваших требований.Надеюсь, это поможет вам.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...