我有一个填充AsyncTask的ListView。在运行时,ListView变为不可见,ProgressBar显示在水平的中心,在AsyncTask完成后消失,并再次显示ListView。现在它看起来像这样:
但是我需要在ListView内部显示ProgressBar并且水平和垂直居中:
这是我的布局标记:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:id="@+id/LinearHeaderProgress"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<ProgressBar
android:id="@+id/HeaderProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ProgressBar>
</LinearLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/listView"/>
</LinearLayout>
我怎样才能做到这一点?
感谢。
答案 0 :(得分:5)
尝试像这样使用RelativeLayout,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/HeaderProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
</ProgressBar>
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>