26

Я пробовал свою руку с recyclerview и плавающей кнопкой действия для приложения. Проблема, с которой я столкнулся, заключается в том, что кнопка с плавающим действием препятствует кнопкам в recyclerview. Я посмотрел, как приложения для Android, такие как приложение для телефона (одно из которых у вас есть контакты, отображаемые в gridvew), предназначены для решения этой проблемы, я вижу, что в нижней части находится пустое пространство, которое дает пространство между recyclerview и кнопкой плавающего действия, пользователь просто нужно прокрутить вниз, чтобы избежать перекрытия. Я попытался добавить представление после recyclerview, но не его не отображалось, также этот вид должен перемещаться вместе со строками recyclerview. Что мне не хватает, чтобы показать представление в конце recyclerview. Мой файл макета:Невозможно добавить пустой вид ниже Recyclerview

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="#6fbababa"> 

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

    <ImageButton 
     android:id="@+id/button_floating_action" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:src="@drawable/ic_fab" 
     android:background="@null" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="12dp" 
     android:layout_marginEnd="12dp" 
     android:layout_marginRight="12dp" 
     android:elevation="2dp"/> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="30dp" 
     android:layout_below="@id/my_recycler_view" 
     android:background="@color/white"/> 

</RelativeLayout> 

enter image description here

Update: Модифицированный код макета, чтобы заставить его работать.

<android.support.v7.widget.RecyclerView 
android:id="@+id/my_recycler_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:clipToPadding="false" 
android:paddingBottom="30dp" 
android:scrollbars="vertical"/> 
+0

Все, что вам нужно - это оставить RecyclerView последним. Посмотрите пример на мой ответ. HTH – Dpedrinha

ответ

43

Добавить нижнее дополнение к RecyclerView. Кроме того, не используйте android:layout_height="wrap_content", если вы не переопределили onMeasure в менеджере компоновки. Существующие менеджеры макета еще не поддерживают обертку содержимого.

Добавьте атрибут android:clipToPadding="false" для достижения цели. Как упоминалось в комментариях.

+1

Добавление дополнения к recyclerview вызывает раздел экрана, который будет занят, который отключает представление к строке в конце экрана. Он не показывает пустое место под последней строкой, а вместо этого показывает над последним – Psypher

+18

Просто решил эту проблему ... нам также нужно добавить android: clipToPadding = "false" в recyclerview..это конечный результат, который сработал для меня Psypher

+1

Работал для меня тоже! –

2

Вот пример (в данном случае listView, но может быть что угодно) под видом ресайклера, который занимает остальную часть высоты родителя. Обратите внимание на атрибуты layout_alignParentBottom и layout_above.

<RelativeLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<ListView 
    android:id="@+id/list_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="none" 
    **android:layout_alignParentBottom="true"** 
    /> 

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

1

Я создал метод полезности для того, чтобы вы могли добавить отступы легко

public void addLastChildPadding(RecyclerView.ViewHolder holder,int padding,int recyclerListSize,int position){ 

if(recyclerListSize-1==position){ 
holder.itemView.setPadding(0,0,0,padding); 
} 
} 
0

Попробуйте сразу

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 


<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:clipToPadding="false"> 

     </android.support.v7.widget.RecyclerView> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="15dp"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:orientation="horizontal"> 

      <android.support.v7.widget.AppCompatButton 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="15dp" 
       android:layout_weight="1" 
       android:background="@drawable/button_primary_color_border" 
       android:text="70%" 
       android:textColor="@android:color/darker_gray" 
       android:textSize="20sp" /> 

      <android.support.v7.widget.AppCompatButton 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="15dp" 
       android:layout_weight="1" 
       android:background="@drawable/button_primary_color_border" 
       android:text="60%" 
       android:textColor="@android:color/darker_gray" 
       android:textSize="20sp" /> 
     </LinearLayout> 
    </RelativeLayout> 

</RelativeLayout> 
</LinearLayout> 

</LinearLayout> 

Удалите изображения и другую строку в соответствии с ваше использование.