Android 空ListVIEW布局不显示在屏幕中部

Android 空ListVIEW布局不显示在屏幕中部,android,android-layout,listview,Android,Android Layout,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

我得到了一个带有
列表视图
的片段:

<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" />


我看到Eclipse的图形布局中的按钮为“代码> EMPTYListListDeals”但当列表为空时,布局显示在屏幕的顶部。为什么它不在中间,就像布局告诉它的那样?

< p>这是因为您的父视图是“代码>线性布局< /代码>,方向是垂直的,而您的空<代码> ViewStub <代码>的高度为<代码> WrAPHEngult。因此,LinearLayout开始从上到下绘制其子对象


您想使用
RelativeLayout
作为父对象。

如果我更改ViewStub的高度以匹配父对象,为什么它也不起作用?有了重力和其他布局,它不应该工作吗?实际上,
gravity
用于其内部子级,您要使用的属性是
layout\u gravity
它将影响重力在其父级中的位置。从xml:android:layout\u gravity=“center”可以看出,在父级布局支持它之前,它不会影响重力。LinearLayout不完全支持它。使用RelativeLayout。
<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" />