android - 如何在 ListView 中放置 ProgressBar?

标签 android android-listview markup android-progressbar

我有一个在 AsyncTask 中填充的 ListView。运行时ListView不可见,ProgressBar显示在水平居中,AsyncTask完成后消失,ListView再次显示。现在看起来像这样:

enter image description here

但我需要在 ListView 内部显示 ProgressBar,并且水平和垂直居中:

enter image description here

这是我的布局标记:

<?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>

我怎样才能做到这一点?

谢谢。

最佳答案

尝试像这样使用 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>

关于android - 如何在 ListView 中放置 ProgressBar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26203440/

相关文章:

android - 为什么 PagerAdapter 的 restoreState() 和 saveState() 不起作用?

Android Studio 没有提供添加新 Activity 的选项

android - 相对缩放 View 及其分层 subview

android - 弹出窗口内的 ListView 高度没有改变

Android 错误 Dx trouble writing output :already prepared

asp.net - ASP.NET 标记中控件属性中的引号

standards - reStructuredText : `Foo` _ or Foo_? 中超链接的标准语法是什么

android - 桌面和移动设备之间的 SVG 渲染不一致 - Arial 是 SVG 中的网络安全字体吗?

android - ListView 布局返回空 View

jquery - 使用 jQuery 将类添加到 ul li 的每个级别