J'utilise DrawerLayout pour afficher Navigation Drawer , dans ce A NavigationView , le code xml est:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<include
android:id="@+id/headerLayout"
layout="@layout/nav_header_dash_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="top"
android:gravity="top" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerNav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/headerLayout"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="@color/white"
android:foregroundGravity="bottom" />
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<include layout="@layout/layout_navigation_list" />
</android.support.design.widget.NavigationView>
Dans le RecyclerView , je n'ai que 3 éléments à afficher, et ils s'alignent en haut du Mise en page RecyclerView dont je ne veux pas. D'où ma question ici est de savoir comment envoyer ces éléments au bas de la RecyclerView (comme indiqué dans l'image).
3 Réponses :
Définissez match_parent à la place du champ wrap_content layout_height dans relativeLayout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:orientation="vertical">
p>
Insérez un ConstraintLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/white"
android:orientation="vertical">
<include
android:id="@+id/headerLayout"
layout="@layout/nav_header_dash_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="top"
android:gravity="top" />
<android.support.constraint.ConstraintLayout
android:layout_below="@id/headerLayout"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerNav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
/>
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
Vous devriez avoir une MATCH_PARENT hauteur au lieu de WRAP_CONTENT dans la disposition relative racine dans le fichier layout_navigation_list.xml . Il semble donc que
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:orientation="vertical"> ... ... ... </RelativeLayout>
Remarques: La gravité ne fonctionnera pas avec les mises en page relatives.