2016-03-29 12 views
0

Jeder Artikel sollte 70% der Bildschirmbreite abdecken. Obwohl 70% des Bildschirms gefüllt sind, erhalte ich 30% Leerraum und der nächste Gegenstand beginnt danach. Hier ist das Layout -Horizontaler RecyclerView nicht wrapping Layout

<?xml version="1.0" encoding="utf-8"?> 
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_weight="4" 
     app:cardCornerRadius="2dp" 
     app:cardElevation="2dp" 
     app:cardPreventCornerOverlap="false" 
     app:cardUseCompatPadding="true" 
     app:contentPadding="2dp" 
     app:layout_widthPercent="70%"> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:orientation="vertical"> 

      <ImageView 
       android:id="@+id/image_test" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="centerCrop"/> 

     </FrameLayout> 
    </android.support.v7.widget.CardView> 
</android.support.percent.PercentRelativeLayout> 
+0

Versuchen einstellen 'App: layout_widthPercent = "70%"' zu 'PercentRelativeLayout' und setzen' CardView' auf 'match_parent' –

+0

Das Problem ist nicht mit diesem Layout, es ist mit dem Layout, das die recyvlerview hält. Wenn Sie layout_margintop an einer beliebigen Stelle hinzugefügt haben, entfernen Sie diese bitte. – Jois

+0

@IvanIvanov Wie können Sie dem PercentRelativeLayout selbst eine prozentuale Breite zuweisen? Das letzte Mal, wenn ich den Prozentsatz überprüfe, ist relativ. – mjosh

Antwort

0

Vor Android Support Library, revision 23.2.1 recyclerView nicht der Höhe betrachtet hat (vertikal) oder Breite (horizontal) seine itemView. Es wickelt es immer auf.

Aber jetzt berücksichtigt es die Höhe oder Breite. In deinem Fall ist es Breite.

Also, machen Sie Ihre layout_width, match_parent-wrap_content

+0

layout_width von recyclerview? – mjosh

+0

Nö .. RecyclerViews untergeordnete Artikelbreite – Sayem

+0

Untergeordnete Artikel ist ein 'PercentRelativeLayout', was bedeutet, dass das Layout 70% des übergeordneten Elements nicht verändert. Sein 'match_parent' aus einem bestimmten Grund, so dass untergeordnete Elemente 70% des Bildschirms einnehmen können. – mjosh

Verwandte Themen