-1
我買了一個ListView
片段:空的ListView佈局在屏幕中間沒有顯示
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layoutDirection="rtl" >
<ListView
android:id="@+id/listViewPlaces"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
<ViewStub
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout="@layout/empty_list_layout" />
和empty_list_layout
:
<Button
android:id="@+id/no_result_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:clickable="false"
android:drawableTop="@drawable/app_icon"
android:text="@string/empty_list"
android:textSize="30sp" />
我在Eclipse的圖形佈局中看到empty_list_layout
的按鈕,但當列表爲空時,佈局顯示在屏幕的頂部。爲什麼它不像佈局所說的那樣在中間?
爲什麼它不工作,如果我改變ViewStub的高度來匹配父母?其重力和其他佈局不應該工作? –
實際上,'gravity'用於它的內部孩子,你想要使用的屬性是'layout_gravity',它會影響重力在其父項中的位置。 –
,你可以從xml中看到:android:layout_gravity =「center」 –