![](/img/trans.png)
[英]how to make progress bar always in the center screen of scroll view and swipe refresh layout?
[英]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.