Benny
Benny

Reputation: 3917

Split Screen In Two (Horizontally or Vertically)

I am trying to build a screen that is split down the middle horizontally when in landscape and vertically when in portrait. I have tried the below, but it does not work like I was expecting. Any help would be greatly appreciated!

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout android:layout_width="wrap_content"
        android:layout_height="fill_parent" android:layout_gravity="left"
        android:orientation="horizontal">
        <ListView android:layout_width="fill_parent" android:id="@+id/lvChoices"
            android:layout_gravity="left" android:layout_height="fill_parent" />
    </LinearLayout>
    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:orientation="horizontal">
        <ListView android:layout_width="fill_parent" android:id="@+id/lvOptions"
            android:layout_gravity="right" android:layout_height="fill_parent" />
    </LinearLayout>
</LinearLayout>

Upvotes: 1

Views: 9118

Answers (1)

Labeeb Panampullan
Labeeb Panampullan

Reputation: 34823

To split down the middle exactly it is better to use android:layout_weight="1" to your each child in your main linear layout
To separate landscape and portrait.

  1. you can use to xml file one in layout-land and other layout-port with android:orientation="horizontal" and android:orientation="vertical" respectively
  2. If you wish to use same xml for both by setting your activity with android:configChanges="orientation", then identify your LinearLayout with its id and use setOrientation(LinearLayout.HORIZONTAL) in the onConfigurationChanged function

Upvotes: 6

Related Questions