简体   繁体   English

为什么我的水平 recyclerview 不会在片段中滚动

[英]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.您应该使用 NestedScrollView 并将所有 Vertical 和 Horizo​​ntal RecyclerViews 放在那里。 Add nestedScrolling behaviour to your RecyclerViews.将nestedScrolling 行为添加到您的RecyclerViews。

You can specify the layout of your reycler either in XML or programmatically:您可以以 XML 或以编程方式指定 reycler 的布局:

XML: 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);

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

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