簡體   English   中英

RecyclerView不滾動

[英]RecyclerView isn't scrolling

我正在制作一個應用程序,其中包含帶有某些項目的recyclerView。 該應用程序使用BottomNavigationView和其他三個片段來顯示一些內容。 現在,這些片段之一僅包含RecyclerView,並且不會滾動。

我已經嘗試過一些方法,例如將RecyclerView的高度從match_parent更改為wrap_content,使用LinearLayout將其包裝,使用NestedScrollView或常規ScrollView,添加app:layout_behavior甚至android:scrollbars。 什么都沒有。

列表中未滾動的布局的XML文件:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="55dp">

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

</FrameLayout>

我將下面的ConstrainedLayout設置為另一個Fragment的父級,它還包含BottomNavigationView(這是我在創建項目btw時由Android Studio生成的):

<android.support.constraint.ConstraintLayout 
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/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:background="@color/colorPrimary"
        app:itemIconTint="@drawable/bottom_nav_selector"
        app:itemTextColor="@drawable/bottom_nav_selector"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

</android.support.constraint.ConstraintLayout>

最后,這是在Fragment的類中,在其中設置RecyclerView:

    adapter = new UserListAdapter(list, getContext(), getLayoutInflater(), container);
    RecyclerView recyclerView = v.findViewById(R.id.rv_users);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

    recyclerView.setAdapter(adapter);

我希望你們中的一個能幫助我!

您是否有足夠的數據可在回收站上列出以便滾動?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM