Android RecyclerView Gravity проблема - PullRequest
2 голосов
/ 23 июня 2019

Я использую DrawerLayout, чтобы показать Navigation Drawer, в этом A NavigationView, код xml:

MyDrawerLayout.xml

<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>

layout_navigation_list.xml

 <?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>

ScreenImage

В RecyclerView у меня есть только 3 элемента, которые нужно показать,и они располагаются на верхней части макета RecyclerView, который я не хочу.Поэтому мой вопрос здесь заключается в том, как отправить эти элементы в нижнюю часть RecyclerView (как показано на рисунке).

Ответы [ 3 ]

1 голос
/ 23 июня 2019

Установите match_parent вместо wrap_content поле layout_height in 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">
0 голосов
/ 23 июня 2019

Вы должны иметь MATCH_PARENT высоту вместо WRAP_CONTENT в корневой относительной компоновке в файле layout_navigation_list.xml. Так выглядит,

<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>

Примечания: Гравитация не будет работать с относительными раскладками.

0 голосов
/ 23 июня 2019

Вставить 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>
...