简体   繁体   中英

why my horizantal recyclerview won't scrolling in fragment

I have two recyclerviews in my fragment one is horizontal and the second is vertical when i scrolling the horizontal recylcer won't scroll but the vertical scroll .. i want both to scroll vertically below my toolbar and i want my toolbar to collapsing what is the problem ?

here is my main activity

<androidx.drawerlayout.widget.DrawerLayout

    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#242a38"
    android:fitsSystemWindows="true"
    tools:context=".ui.HomeActivity">


    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

      <FrameLayout
                android:id="@+id/fragment_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent">


            </FrameLayout>


    </androidx.coordinatorlayout.widget.CoordinatorLayout>




    <com.ismaeldivita.chipnavigation.ChipNavigationBar
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="72dp"
        android:layout_gravity="bottom"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="0dp"
        android:background="@drawable/round"
        android:elevation="16dp"
        android:padding="8dp"
        app:cnb_menuResource="@menu/bottom_navigation_menu" />


    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#242a38"
        android:fitsSystemWindows="true"
        android:foregroundGravity="top"
        app:headerLayout="@layout/nav_header"
        app:itemIconTint="#FFFFFF"
        app:itemTextColor="#FFFFFF"
        app:menu="@menu/drawer_menu">


    </com.google.android.material.navigation.NavigationView>


</androidx.drawerlayout.widget.DrawerLayout>

my home fragment

   <androidx.coordinatorlayout.widget.CoordinatorLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#242a38"
    tools:context=".ui.HomeFragment">



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

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">



        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/myrecycler"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="11dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView10" />

        <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/posts_recycler"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:layout_marginTop="20dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/myrecycler" />




    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

You should use NestedScrollView and place all your Vertical and Horizontal RecyclerViews there. Add nestedScrolling behaviour to your RecyclerViews.

You can specify the layout of your reycler either in XML or programmatically:

XML:

<android.support.v7.widget.RecyclerView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
 />

CODE :

LinearLayoutManager layoutManager
    = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);

RecyclerView myList = (RecyclerView) findViewById(R.id.my_recycler_view);
myList.setLayoutManager(layoutManager);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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