Reputation: 17
I'm trying to get this layout
https://i.sstatic.net/3lTHs.png
But for some reason the ListView keeps getting put to the side of the 3rd button and thus off the screen
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:weightSum="1.0">
<Button
android:layout_weight=".33"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="Add"
android:onClick="addPerson"
android:id="@+id/add" />
<Button
android:layout_weight=".33"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="Edit"
android:id="@+id/edit" />
<Button
android:layout_weight=".33"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="Delete"
android:id="@+id/delete" />
Upvotes: 0
Views: 40
Reputation: 1748
Use layout_weight so it can go down for as long as it can:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:weightSum="1.0"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<Button
android:id="@+id/add"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:onClick="addPerson"
android:text="Add" />
<Button
android:id="@+id/edit"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:text="Edit" />
<Button
android:id="@+id/delete"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:text="Delete" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Upvotes: 0
Reputation: 945
You need to define two LinearLayouts, one with vertical orientation (for 3 buttons and the listview) and another with horizontal (for buttons) :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:weightSum="1.0"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<Button
android:layout_weight=".33"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="Add"
android:onClick="addPerson"
android:id="@+id/add" />
<Button
android:layout_weight=".33"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="Edit"
android:id="@+id/edit" />
<Button
android:layout_weight=".33"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="Delete"
android:id="@+id/delete" />
</LinearLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
etc...etc
/>
</LinearLayout>
Upvotes: 1