![](/img/trans.png)
[英]Android RecyclerView inside a RelativeLayout not scrolling properly
[英]RecyclerView inside fragment not scrolling in Android API 22
我在Fragment內的ScrollView中創建了RecyclerView,以顯示多個通知。 在Android API 28上,它運行良好,但在API 22上,它沒有滾動,除非我關閉片段並再次打開它,然后它在新位置顯示RecyclerView(就像我滾動了一樣,當片段處於顯示)。
我試過了:
1-將ScrollView更改為NestedScrollView
2-完全刪除ScrollView並僅使用RecyclerView
3-刪除RecyclerView元素的onClickListeners
這是片段的代碼
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/common_google_signin_btn_text_dark_default"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:padding="20dp"
android:id="@+id/my_recycler_view_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
編輯:我刪除了滾動布局,但問題仍然存在。 我也嘗試過,它可以在android API 23及更高版本上完美運行。 滾動只會停止在android API 22及更早版本上的工作。
我只是嘗試獨自保留回收器視圖,但它仍然沒有滾動。
原來問題出在我使用該片段的另一個文件中,那里有一個AppBarLayout,由於某種原因,它阻止了舊API的滾動。 刪除了AppBarLayout,它工作正常。
編輯:我找到了一個不需要刪除AppBarLayout的更好的解決方案,而不是正常地隱藏和取消隱藏片段,我使用了setVisibility(GONE / VISIVILE),並且它也以某種方式起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.