2016-07-27 2 views
0

У меня есть пробелы в recyclerview моего приложения, и я не знаю, почему есть, потому что я сделал что-то, используя recyclerview и этот адаптер, и не добавил нежелательное пространство ... но теперь это. Помогите пожалуйстаНежелательные пробелы в элементах recycliewiew в android

First screenshot

Вот мой дом макет

<?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" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="ideias.prime.mungano.Home" 
    tools:showIn="@layout/activity_home"> 

    <android.support.v7.widget.RecyclerView 
    android:id="@+id/clients_rv" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 
    </RelativeLayout> 

А вот модель recyclerview Item

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

<android.support.v7.widget.CardView 
    android:id="@+id/cl_CardView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="?android:attr/selectableItemBackground" 
    android:clickable="true" 
    card_view:cardBackgroundColor="@color/colorAccent" 
    card_view:cardCornerRadius="12dp" 
    card_view:cardUseCompatPadding="true" 
    card_view:contentPadding="6dp"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <TextView 
      android:id="@+id/cl_name" 
      android:layout_width="69dp" 
      android:layout_height="wrap_content" 
      android:layout_alignParentStart="true" 
      android:ellipsize="end" 
      android:fitsSystemWindows="true" 
      android:padding="4dp" 
      android:singleLine="true" 
      android:text="@string/cl_name" 
      android:textColor="@color/colorPrimaryText" 
      android:textSize="15sp" 
      android:typeface="serif" /> 

     <TextView 
      android:id="@+id/nome_do_cliente" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toEndOf="@+id/cl_name" 
      android:ellipsize="end" 
      android:fitsSystemWindows="true" 
      android:padding="4dp" 
      android:singleLine="true" 
      android:text="@string/programmer" 
      android:textColor="@color/colorPrimaryText" 
      android:textSize="15sp" 
      android:typeface="serif" /> 

     <TextView 
      android:id="@+id/cl_work" 
      android:layout_width="82dp" 
      android:layout_height="wrap_content" 
      android:layout_alignParentStart="true" 
      android:layout_below="@+id/cl_name" 
      android:ellipsize="end" 
      android:fitsSystemWindows="true" 
      android:padding="4dp" 
      android:singleLine="true" 
      android:text="@string/cl_work" 
      android:textAlignment="center" 
      android:textColor="@color/colorPrimaryText" 
      android:textSize="15sp" 
      android:typeface="serif" /> 

     <TextView 
      android:id="@+id/trabalho_do_cliente" 
      android:layout_width="99dp" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/cl_work" 
      android:layout_toEndOf="@+id/cl_work" 
      android:ellipsize="end" 
      android:fitsSystemWindows="true" 
      android:singleLine="true" 
      android:text="@string/primeIdeas" 
      android:textColor="@color/colorPrimaryText" 
      android:textSize="15sp" 
      android:typeface="serif" /> 

     <TextView 
      android:id="@+id/cl_phone" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentStart="true" 
      android:layout_below="@+id/cl_work" 
      android:fitsSystemWindows="true" 
      android:padding="4dp" 
      android:text="@string/cl_phone" 
      android:textColor="@color/colorPrimaryText" 
      android:textSize="15sp" /> 

     <TextView 
      android:id="@+id/telefone_do_cliente" 
      android:layout_width="99dp" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/cl_phone" 
      android:layout_toEndOf="@+id/cl_work" 
      android:ellipsize="end" 
      android:fitsSystemWindows="true" 
      android:singleLine="true" 
      android:text="@string/primeIdeas" 
      android:textColor="@color/colorPrimaryText" 
      android:textSize="15sp" 
      android:typeface="serif" /> 

     <TextView 
      android:id="@+id/cl_LP" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/trabalho_do_cliente" 
      android:layout_alignParentEnd="true" 
      android:ellipsize="end" 
      android:ems="10" 
      android:fitsSystemWindows="true" 
      android:padding="4dp" 
      android:singleLine="true" 
      android:text="@string/cl_LP" 
      android:textColor="@color/colorPrimaryText" 
      android:textSize="15sp" /> 

     <TextView 
      android:id="@+id/cl_LP_info" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/telefone_do_cliente" 
      android:layout_alignParentEnd="true" 
      android:ellipsize="end" 
      android:ems="10" 
      android:fitsSystemWindows="true" 
      android:padding="4dp" 
      android:singleLine="true" 
      android:text="@string/cl_Lp_info" 
      android:textColor="@color/colorPrimaryText" 
      android:textSize="15sp" /> 

     <TextView 
      android:id="@+id/cl_id" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="53dp" 
      android:layout_toEndOf="@+id/cl_phone" 
      android:ellipsize="end" 
      android:ems="10" 
      android:fitsSystemWindows="true" 
      android:padding="4dp" 
      android:singleLine="true" 
      android:text="@string/Id" 
      android:textColor="@color/colorPrimaryText" 
      android:textSize="15sp" 
      android:visibility="gone" /> 
    </RelativeLayout> 
</android.support.v7.widget.CardView> 
</LinearLayout> 

А вот адаптер

public class Rv_adapter extends RecyclerView.Adapter<Rv_adapter.Holder> { 
private Context context; 
private List<Model> list = new ArrayList<>(); 
private Face f; 

public Rv_adapter(Context c) { 
    context = c; 
} 

public Rv_adapter(Context c, List<Model> l) { 
    this.context = c; 
    this.list = l; 
} 

public void Listenner(Face interfaCe) { 
    this.f = interfaCe; 
} 

@Override 
public Holder onCreateViewHolder(ViewGroup parent, int viewType) { 
    View v = LayoutInflater.from(context.getApplicationContext()).inflate(R.layout.rv_model, parent, false); 
    return new Holder(v); 
} 

@Override 
public void onBindViewHolder(Holder holder, int position) { 
    holder.Id.setText(list.get(position).getId()); 
    holder.Name.setText(list.get(position).getName()); 
    holder.Lp.setText(list.get(position).getLp()); 
    holder.Phone.setText(list.get(position).getPhone()); 
    holder.Work.setText(list.get(position).getWork()); 
} 

@Override 
public int getItemCount() { 
    return list.size(); 
} 

class Holder extends RecyclerView.ViewHolder { 
    private CardView c; 
    private TextView Id, Name, Work, Phone, Lp; 

    public Holder(View i) { 
     super(i); 
     c = (CardView) i.findViewById(R.id.cl_CardView); 
     Id = (TextView) i.findViewById(R.id.cl_id); 
     Name = (TextView) i.findViewById(R.id.nome_do_cliente); 
     Work = (TextView) i.findViewById(R.id.trabalho_do_cliente); 
     Phone = (TextView) i.findViewById(R.id.telefone_do_cliente); 
     Lp = (TextView) i.findViewById(R.id.cl_LP_info); 
    } 
} // end 

public interface Face { 
    void Clicked(View v, int position, String cl_id); 
} 
} 

Здесь идет скриншоты нежелательных пространств на recyclerview

First

Secound

Third

+0

Пожалуйста, разместите снимок экрана проблемы, чтобы продемонстрировать, что такое нежелательное пространство. – bpachev

+0

@bpachev: Я отредактировал мой пост, добавив скриншот recyclerview с нежелательными пробелами –

+0

нет скриншота. можете ли вы проверить, правильно ли вы добавили его? – ono

ответ

0

изменить свой recyclerview Высота от android:layout_height="match_parent" до android:layout_height="wrap_content".

и почему вы даете поведение прокрутки своему относительному расположению ??? RecyclerView уже есть!

+0

Зачем вам это делать? Вы не будете 'wrap_content' ListView ... –

+0

, но он использует RecyclerView, а не ListView. –

+0

. RecyclerView по сути является заменой для списка. Я хотел бы надеяться, что нужно, чтобы список занимал весь экран, а не только размер его дочерних элементов. –

0

Там нет никаких проблем с recyclerview, вы должны внести изменения в R.layout.rv_model файл. Вы установили android:fitsSystemWindows="true" на <TextView>.

В большинстве случаев ваше приложение не нужно рисовать под панелью состояния или панелью навигации, но если вы это сделаете: вы должны убедиться, что интерактивные элементы (например, кнопки) не скрыты под ними. Это то, что поведение по умолчанию атрибута android: fitsSystemWindows = "true" дает вам: он устанавливает заполнение представления для обеспечения того, чтобы содержимое не накладывалось на системные окна.

Несколько вещей, которые нужно иметь в виду:

fitsSystemWindows применяется глубина первых - вопросы упорядочения: это первый View, который потребляет врезки, что делает разницу

вставках всегда относительно полного окна - вставки могут быть применены даже до того, как будет выполнен макет, поэтому не предполагайте, что поведение по умолчанию ничего не знает о позиции представления при применении его заполнения.

Любое другое дополнение, которое вы установили, перезаписывается - вы заметите, что paddingLeft/paddingTop/etc неэффективен, если вы используете android: fitsSystemWindows = "true" на том же представлении

И во многих случаях, таких как полноэкранное воспроизведение видео, этого достаточно. У вас будет полный просмотр с отсутствием атрибута и еще одна полноэкранная ViewGroup с android: fitsSystemWindows = "true" для ваших элементов управления, которые вы хотите вставить.

Возможно, вы хотите, чтобы ваш RecyclerView прокручивался под прозрачной навигационной панелью - с помощью android: fitsSystemWindows = "true" в сочетании с android: clipToPadding = "false", ваш прокручиваемый контент будет за элементами управления, но при прокрутке снизу, последний элемент будет по-прежнему заполняться над навигационной панелью (а не скрываться снизу!).

Проверьте, если вы хотите получить больше информации о android:fitsSystemWindows

0

Вашего макета элемента заполнение одной длины экрана каждого.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/tools" 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" <!-- Here needs to be wrap_content --> 
android:orientation="vertical"> 

<android.support.v7.widget.CardView 
    android:id="@+id/cl_CardView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 

И удалить android:fitsSystemWindows="true" из TextViews, потому что им не нужно, чтобы соответствовать окно системы.

Смежные вопросы