Reputation: 3917
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
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.
layout-land
and other layout-port
with android:orientation="horizontal"
and android:orientation="vertical"
respectivelyandroid:configChanges="orientation"
, then identify your LinearLayout with its id and use setOrientation(LinearLayout.HORIZONTAL)
in the onConfigurationChanged
function Upvotes: 6