繁体   English   中英

如何使包含滚动刷新布局的视图可滚动?

[英]How to make a view scrollable which contains swipe refresh layout?

我试图使包含滚动刷新布局的视图可滚动。 我的xml在这里

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:scrollbars="none"
    xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <androidx.cardview.widget.CardView
        android:id="@+id/post"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <include layout="@layout/layout_post" />
    </androidx.cardview.widget.CardView>

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout_comments"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/comment_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

但这并没有显示recycler-view 仅显示Cardview内容 在此处输入图片说明 在不使用NestedScrollView ,显示如下。 它同时显示了cardivew和recyler视图的内容。 但是我想让我的整个屏幕都可滚动。 我做错了什么? 在此处输入图片说明

SwipeRefreshLayout将占据整个高度,在这种情况下,您需要将其添加为xml的父级,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh_layout_comments"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <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="match_parent"
            android:orientation="vertical">

            <androidx.cardview.widget.CardView
                android:id="@+id/post"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

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

            </androidx.cardview.widget.CardView>

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

    </androidx.core.widget.NestedScrollView>

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM