【问题标题】:ProgressBar not centered on fragmentProgressBar 不以片段为中心
【发布时间】:2017-06-14 12:53:51
【问题描述】:

我在片段中有一个回收器视图,我想在填充数据之前显示进度条。 ProgressBar 显示在 actionBar 附近的 centerTop 上,而不是屏幕中间。下面是我的 recyclerview 和进度条的布局 xml。我希望进度条显示在屏幕中间。

recyclerview.xml

<?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="false"/>

            <ProgressBar
                android:id="@+id/progressBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"/>

        </RelativeLayout>

    </android.support.v4.widget.NestedScrollView>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingTop="?attr/actionBarSize"
    android:fitsSystemWindows="true"
    tools:context="com.example.test.MainActivity">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include layout="@layout/recyclerview" />

    </android.support.design.widget.CoordinatorLayout>
</RelativeLayout>

这就是我得到的

【问题讨论】:

  • 尝试将android:layout_height="match_parent" 用于RecyclerView
  • @A.A.它仍然无法正常工作

标签: android android-fragments android-recyclerview android-progressbar


【解决方案1】:

我前段时间遇到过这个问题,您也可以尝试列出 列出Recyclerview之前的进度条

如果您按照您的要求保留它,请尝试添加android:layout_below="@id/recyclerview"

【讨论】:

    【解决方案2】:

    请改用此代码。我已经测试过了

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center">
    
            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="false"/>
    
            <ProgressBar
                android:id="@+id/progressBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"/>
    
        </FrameLayout>
    
    </android.support.v4.widget.NestedScrollView>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-09
      • 2017-04-20
      • 2016-11-15
      • 1970-01-01
      • 2022-08-13
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多