Android 在recyclerview的中心显示加载视图

Android 在recyclerview的中心显示加载视图,android,android-layout,android-constraintlayout,Android,Android Layout,Android Constraintlayout,我有一个使用协调器布局作为根的布局,它有一个可折叠的工具栏和一个标题视图。在下面我有一个recyclerview,在那里我显示一个项目列表 在recyclerview的中心显示loadingView时出现问题。我一直在尝试使用约束布局,但没有成功。因此,如果标题被折叠或展开,它应该始终显示在recyclerview的中心,而不是实际屏幕 以下是我的布局: <?xml version="1.0" encoding="utf-8"?> <android.support.design

我有一个使用协调器布局作为根的布局,它有一个可折叠的工具栏和一个标题视图。在下面我有一个recyclerview,在那里我显示一个项目列表

在recyclerview的中心显示loadingView时出现问题。我一直在尝试使用约束布局,但没有成功。因此,如果标题被折叠或展开,它应该始终显示在recyclerview的中心,而不是实际屏幕

以下是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/search_result_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:collapsedTitleGravity="left"
            app:contentScrim="@color/toolbar_color"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

            <include
                android:id="@+id/header"
                layout="@layout/list_header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.3" />

            <cToolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin" />

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

        <CustomOverlayLoadingView
            android:id="@+id/loadingView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="@id/contentView"
            app:layout_constraintTop_toTopOf="@id/contentView"
            android:visibility="gone"
            tools:visibility="visible" />
    </android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout> 


RecyclerView
设置适当的约束应该在这里有所帮助。以下是主要内容的
ConstraintLayout
的外观:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/contentView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <CustomOverlayLoadingView
        android:id="@+id/loadingView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="@id/contentView"
        app:layout_constraintEnd_toEndOf="@id/contentView"
        app:layout_constraintStart_toStartOf="@id/contentView"
        app:layout_constraintTop_toTopOf="@id/contentView"
        android:visibility="gone"
        tools:visibility="visible" />

</android.support.constraint.ConstraintLayout>

RecyclerView
设置适当的约束应该在这里有所帮助。以下是主要内容的
ConstraintLayout
的外观:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/contentView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <CustomOverlayLoadingView
        android:id="@+id/loadingView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="@id/contentView"
        app:layout_constraintEnd_toEndOf="@id/contentView"
        app:layout_constraintStart_toStartOf="@id/contentView"
        app:layout_constraintTop_toTopOf="@id/contentView"
        android:visibility="gone"
        tools:visibility="visible" />

</android.support.constraint.ConstraintLayout>

试试这个…:)


试试这个…:)



谢谢您的回答。我已经做出了这些改变。但是,图像似乎在标题下方进行了调整。有没有办法将其居中于recyclerview的范围内?将
app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
属性从
ConstraintLayout
移动到
recyclerview
应该会有所帮助。更新了我的答案。谢谢你的回答。我已经做出了这些改变。但是,图像似乎在标题下方进行了调整。有没有办法将其居中于recyclerview的范围内?将
app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
属性从
ConstraintLayout
移动到
recyclerview
应该会有所帮助。更新了我的答案。