2016-07-27 15 views
0

Ich habe Leerzeichen auf Recyclerview meiner App und ich weiß nicht, warum dort sind, weil ich das samething mit der recyclerview und diesem Adapter getan habe und nicht unerwünschten Speicherplatz hinzugefügt ... aber jetzt es ist. Hilfe bitteUnerwünschte Leerzeichen in Recyclerview-Elementen in Android

First screenshot

Hier ist meine Heimat Layout

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

Und hier ist das recyclerview Artikel Modell

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

Und hier ist der Adapter

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); 
} 
} 

geht hier die Screenshots der unerwünschten Plätze auf dem recyclerview

First

Secound

Third

+0

Bitte zeigen Sie einen Screenshot des Problems an, um den unerwünschten Speicherplatz zu demonstrieren. – bpachev

+0

@bpachev: Ich habe gerade meinen Beitrag bearbeitet, indem ich den Screenshot der Recycleransicht mit den unerwünschten Leerzeichen –

+0

hinzugefügt habe, es gibt keinen Screenshot. Können Sie überprüfen, ob Sie es richtig hinzugefügt haben? – ono

Antwort

0

Änderung Ihrer recyclerview Höhe von android:layout_height="match_parent" zu android:layout_height="wrap_content".

und warum geben Sie Scroll-Verhalten zu Ihrem relativen Layout ??? RecyclerView hat das schon!

+0

Warum würden Sie das tun? Du würdest keinen ListView "wrap_content" ... –

+0

, aber er benutzt RecyclerView nicht ListView –

+0

Ein RecyclerView ist im Wesentlichen der Ersatz für eine Liste. Ich würde hoffen, dass eine Liste den gesamten Bildschirm einnimmt, nicht nur die Größe der Elemente der Kinder. –

0

Es gibt kein Problem mit Ihrem recyclerview, sollten Sie Änderungen in R.layout.rv_model Datei. Sie haben die Eigenschaft android:fitsSystemWindows="true" auf <TextView> festgelegt.

Die meiste Zeit muss Ihre App nicht unter der Statusleiste oder der Navigationsleiste zeichnen, aber wenn Sie dies tun, müssen Sie sicherstellen, dass interaktive Elemente (wie Schaltflächen) nicht darunter verborgen sind. Das gibt Ihnen das Standardverhalten des android: fitsSystemWindows = "true" -Attributs: Es legt das Padding der View fest, um sicherzustellen, dass der Inhalt die Systemfenster nicht überlagert. es ist die erste Ansicht, dass die Einsätze verbraucht, die immer bezogen auf das volle Fenster einen Unterschied

Einschübe sind macht -: -:

Ein paar Dinge im Auge zu behalten Angelegenheiten Bestellung

fitsSystemWindows werden Tiefe zuerst angewandt Sie können auch vor der Ausführung des Layouts auf die Verwendung von Einfügungen verzichten. Nehmen Sie daher beim Aufsetzen des Auffüllens nicht an, dass das Standardverhalten etwas über die Position einer Ansicht weiß.

Alle anderen von Ihnen festgelegten Auffülloptionen werden überschrieben. paddingTop/etc ist unwirksam, wenn Sie verwenden android: fitsSystemWindows = "True" auf der gleichen Ansicht

Und in vielen Fällen, wie eine Vollbild-Video-Wiedergabe, das reicht. Sie haben Ihre vollständige Anschnittansicht ohne Attribut und eine andere ViewGroup im Vollbildmodus mit android: fitsSystemWindows = "true" für Ihre Steuerelemente, die Sie einfügen möchten.

Oder vielleicht möchten Sie Ihre RecyclerView unter einer transparenten Navigationsleiste scrollen - mit Android: fitsSystemWindows = "true" in Verbindung mit Android: clipToPadding = "false", wird der Bildlauf Inhalt hinter den Steuerelementen, aber beim Scrollen ganz unten ist das letzte Element immer noch so gepolstert, dass es über der Navigationsleiste liegt (statt darunter versteckt zu sein!).

Überprüfen Sie, ob Sie weitere Informationen wünschen über android:fitsSystemWindows

0

Ihr Artikel Layout jeder Länge des Bildschirms füllt.

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

Und entfernen android:fitsSystemWindows="true" aus der Textviews, weil sie das System Fenster nicht passen müssen.

Verwandte Themen