Buttons added under ReciclerView do not appear

2

I'm using a LinearLayout with a ReciclerView and 3 buttons underneath it.

I'm doing this, but ReciclerView takes up the entire screen and the buttons do not appear.

<?xmlversion="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/salmao"
    tools:context="br.com.robson.boascompras.ListasComprasActivity">

    <android.support.v7.widget.RecyclerView
            android:id="@+id/my_recycler_view"
            android:scrollbars="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/editar"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/excluir"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/nova_lista"/>
    </LinearLayout>
</LinearLayout>
    
asked by anonymous 24.01.2017 / 22:37

1 answer

2

You can not use android:layout_height="wrap_content" , in a RecyclerView or ListView, when the number of items exceeds the screen size.

wrap_content means "make me big enough to display all my content". When the required space is larger than the screen, RecyclerView occupies the entire space, pushing everything underneath it off the screen.

Change% from% to% with% and assign it a weight with android:layout_height="wrap_content" :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/salmao"
    tools:context="br.com.robson.boascompras.ListasComprasActivity">

    <android.support.v7.widget.RecyclerView
            android:id="@+id/my_recycler_view"
            android:scrollbars="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/editar"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/excluir"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/nova_lista"/>
    </LinearLayout>
</LinearLayout>
    
24.01.2017 / 23:15