-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” –