Reputation: 12783
Any idea why the footer of my list view is always on the left? Here's my xml layout. Footer just added and removed as more data needs loaded. I want theTextView and ProgressBar to be center
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="12sp"
android:textColor="@color/author_text"
android:text="LOADING DATA..."
/>
<ProgressBar
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginLeft="10dp"
/>
</LinearLayout>
Upvotes: 1
Views: 1167
Reputation: 12783
Okay, so the problem was NOT with the footer view shown in the OP; it indeed works just fine. The problem was my ListView had the layout_width attribute set to wrap_content. This works just fine for all the list renderers, but not for the footer. Changing the ListView to fill_parent fixed it
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/MyList"
/>
thanks gang [SOLVED]
Upvotes: 7
Reputation: 234795
A horizontal LinearLayout will lay its views out left-to-right. It ignores any gravity or layout_gravity attributes when determining horizontal positioning (although these will affect vertical positioning). You'll need to use a RelativeLayout or else nest a vertical LinearLayout to get horizontal centering of views.
Alternatively, you could give the TextView a layout_weight of 1, which will cause it to take up any extra space. Since it will center its text, that should give you the effect you want.
EDIT: Now that I understand what you want, this ought to do it:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="12sp"
android:textColor="@color/author_text"
android:text="LOADING DATA..."
/>
<ProgressBar
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginLeft="10dp"
/>
</LinearLayout>
</LinearLayout>
You can maybe avoid the nested LinearLayouts by using a RelativeLayout in some way, but this came to mind first.
Upvotes: 1