5

Folks,Impossibile rimuovere spazio tra gli elementi a schede - Scorrevole RecyclerView

Sono fuori di opzioni durante il tentativo di rimozione di spazio tra gli elementi a schede nella mia recyclerview sotto è l'uscita di corrente. Si prega di suggerire.

enter image description here

<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#303030" 
    android:id="@+id/cv" 
    android:layout_marginTop="2dip" 
    android:layout_marginBottom="2dip" 
    card_view:cardUseCompatPadding="true" 
    card_view:cardElevation="5dp" 
    android:foreground="?android:attr/selectableItemBackground" 
    > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="80dp" 
     android:padding="5dp" 
     android:longClickable="true" 
     android:background="#303030"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/person_photo" 
      android:background="@drawable/vector_red" 
      android:layout_alignBottom="@+id/txtSub" /> 


     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Large Text" 
      android:id="@+id/txtMain" 
      android:layout_alignParentTop="true" 
      android:layout_toRightOf="@+id/person_photo" 
      android:layout_toEndOf="@+id/person_photo" 
      android:elevation="4dp" 
      android:textSize="20dp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:text="Small Text" 
      android:id="@+id/txtSub" 
      android:layout_below="@+id/txtMain" 
      android:layout_toRightOf="@+id/person_photo" 
      android:layout_toEndOf="@+id/person_photo" /> 

    </RelativeLayout> 

</android.support.v7.widget.CardView> 

mio punto di vista Recycler

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="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" 
tools:context=".HomeFragment"> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/rv" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="vertical" 
    card_view:cardUseCompatPadding="false" 
    card_view:cardPreventCornerOverlap="false" 
    android:background="#0fffffff" /> 

</RelativeLayout> 
+0

Dupe di http://stackoverflow.com/questions/34240078/modify-cardview-padding? Anche questo non ha una risposta, sfortunatamente. – alzee

+0

Giusto ma il padding è comparativamente ok, ottengo un cardview dall'aspetto brutto ,. serve una vista compatta almeno. – xtechkid

+0

puoi pubblicare uno screenshot di quello che vuoi? @xtechkid – kId

risposta

4

non ho implementato un RecyclerView, però ho replicato due file in un layout lineare, meno l'imbottitura dalla tua domanda iniziale:

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


    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:background="#303030" 
     android:id="@+id/cv1" 
     card_view:cardElevation="5dp" 
     android:foreground="?android:attr/selectableItemBackground" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="80dp" 
      android:layout_margin="4dp" 
      android:longClickable="true" 
      android:background="#303030"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/person_photo" 
       android:background="@drawable/vector_red" 
       android:layout_alignBottom="@+id/txtSub" /> 


      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Large Text" 
       android:id="@+id/txtMain" 
       android:layout_alignParentTop="true" 
       android:layout_toRightOf="@+id/person_photo" 
       android:layout_toEndOf="@+id/person_photo" 
       android:elevation="4dp" 
       android:textSize="20dp" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:text="Small Text" 
       android:id="@+id/txtSub" 
       android:layout_below="@+id/txtMain" 
       android:layout_toRightOf="@+id/person_photo" 
       android:layout_toEndOf="@+id/person_photo" /> 

     </RelativeLayout> 

    </android.support.v7.widget.CardView> 
    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:background="#303030" 
     android:id="@+id/cv1" 
     card_view:cardElevation="5dp" 
     android:foreground="?android:attr/selectableItemBackground" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="80dp" 
      android:layout_margin="4dp" 
      android:longClickable="true" 
      android:background="#303030"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/person_photo" 
       android:background="@drawable/vector_red" 
       android:layout_alignBottom="@+id/txtSub" /> 


      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Large Text" 
       android:id="@+id/txtMain" 
       android:layout_alignParentTop="true" 
       android:layout_toRightOf="@+id/person_photo" 
       android:layout_toEndOf="@+id/person_photo" 
       android:elevation="4dp" 
       android:textSize="20dp" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:text="Small Text" 
       android:id="@+id/txtSub" 
       android:layout_below="@+id/txtMain" 
       android:layout_toRightOf="@+id/person_photo" 
       android:layout_toEndOf="@+id/person_photo" /> 

     </RelativeLayout> 

    </android.support.v7.widget.CardView> 

</LinearLayout> 

giocare con l'imbottitura e si ottengono risultati migliori. Puoi anche provare ad aggiungere un colore di sfondo alla tua carta, quindi puoi liberarti dei margini di layout nel tuo RelativeLayout!

+0

fammi controllare e tornare – xtechkid

+0

Skynet hai salvato il giorno, grazie. !! – xtechkid

+0

Sono contento che mi abbia aiutato :) – Skynet

1

Potete per favore provare questo?

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

Ho controllato, funziona bene per me.

Controllare screenshot:

enter image description here

Spero che questo vi aiuterà.

0

modificare il layout di scheda per

<android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#303030" 
     android:id="@+id/cv" 
     card_view:cardCornerRadius="2dp" 
     card_view:cardElevation="2dp" 
     card_view:cardPreventCornerOverlap="false" 
     card_view:cardUseCompatPadding="true"> 
1

Tutto quello che dovete fare è rimuovere le seguenti due righe dal XML per il CardLayout:

android:layout_marginTop="2dip" 
android:layout_marginBottom="2dip" 

Quello che fa è imposta la separazione tra la due layout, in questo caso hai 4dip (2 in alto e 2 in basso). Puoi anche provare a ridurlo a 1 dip e verificare l'effetto che ti dà.

Spero che questo aiuti :)

0

Nella cambiamento xml vista carta della larghezza di layout genitore complessiva per avvolgere il contenuto.

android:layout_width="math_parent" 

a

android:layout_width="wrap_content"  
Problemi correlati