滑动刷新布局下的RecyclerView未显示在嵌套滚动视图中

时间:2019-06-20 06:30:01

标签: android android-layout

我在滚动视图下的活动中有视图寻呼机和recyclerview。我在刷卡刷新布局下使用recyclerview。我的问题是当我在不使用刷卡刷新布局的情况下使用recyclerview时,它显示在布局中,如果我将其包装在刷卡下刷新布局,则它不会显示在布局中。

这是我下面的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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Home"
android:orientation="vertical"
android:id="@+id/linearHome"
android:paddingBottom="16dp"
android:layout_marginTop="10dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:layout_marginBottom="50dp">

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

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="130dp"
        android:id="@+id/homeOffers"/>

    <android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/indicator"
        app:tabGravity="center"
        app:tabIndicatorHeight="0dp"
        app:tabBackground="@drawable/tab_selector"/>

   <android.support.v4.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/refresh">

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

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

 </LinearLayout>

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

</RelativeLayout>

请让我知道如何实现所需的布局。任何帮助将不胜感激。

谢谢

1 个答案:

答案 0 :(得分:1)

尝试一下

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/linearHome"
    android:paddingBottom="16dp"
    android:layout_marginTop="10dp"
    android:paddingLeft="12dp"
    android:paddingRight="12dp"
    android:layout_marginBottom="50dp">

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

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:scrollbars="none">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <androidx.viewpager.widget.ViewPager
                android:layout_width="match_parent"
                android:layout_height="130dp"
                android:id="@+id/homeOffers"/>

            <com.google.android.material.tabs.TabLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/indicator"
                app:tabGravity="center"
                app:tabIndicatorHeight="0dp"
                />

            <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:id="@+id/refresh">

                <androidx.recyclerview.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/recycle"/>

            </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

        </LinearLayout>

    </androidx.core.widget.NestedScrollView>

</RelativeLayout>

输出

enter image description here

相关问题