Ceci est mon code-
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/frame1" android:layout_width="match_parent" android:layout_height="300dp" android:text="Recruitment Responses" android:gravity="center" android:textSize="30sp" android:textColor="#fff" android:background="@drawable/bg_rounded1" /> <androidx.recyclerview.widget.RecyclerView android:id="@+id/my_recycler_view" android:padding="16dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/frame1" android:background="#f9fafc"/> </RelativeLayout> </ScrollView> </RelativeLayout>
3 Réponses :
Essayez ceci:
recyclerView.setScrollView(true);
Voici le Documentation à Androidx.RecyClerview.Widget. Recyclerview code>. Trouvez-vous des
SetscrollView () CODE> Méthode là-bas?
@Wrichik bassu c'est secret
Ajout d'un <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/frame1"
android:layout_width="match_parent"
android:layout_height="300dp"
android:text="Recruitment Responses"
android:gravity="center"
android:textSize="30sp"
android:textColor="#fff"
android:background="@drawable/bg_rounded1"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:padding="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/frame1"
android:background="#f9fafc"/>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
Essayez-le dans votre activité:
recyclerView.setNestedScrollingEnabled(false);
Les vues de nidification qui font défiler dans la même direction (horizontale / verticale) ne sont généralement pas une bonne idée.
Essayez d'utiliser CoordinatorLayout, CollapsibletoolBar pour atteindre le comportement. Utilisation d'un RECYCLERView avec une hauteur définie sur
wrap_content code> n'est pas une bonne idée si vous avez un grand ensemble d'articles.