I know this can be very easily done by using a Relative Layout but I feel what I am doing is correct and should give me the desired result with the Linear Layout itself. But for some reason, when I run on this on Google Nexus 7 running Android JB 4.1.2, I see the button and the text view immediately after the list view items. If the list view is empty, I see them at the top of the screen. Am I doing something wrong?? Here is my xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/attachments_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
android:orientation="vertical">
<ListView
android:id="@+id/mtg_attachments"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="@+id/attach_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/delete"
android:textSize="22sp" />
<TextView
android:text="@string/attach_warning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp" />
</LinearLayout>
If you want to center an item in the middle of the screen don’t use a LinearLayout as these are meant for displaying a number of items in a row stacked one after another.
Use a RelativeLayout instead.
So replace:
for the relevant
RelativeLayoutoption: