2015-12-15 19 views
5

Bu yüzden bir ImageView arka plan olarak ve bunun üzerine bir Yatay RecyclerView var, buradaki şey, RecyclerView öğesinin ekranın solundaki dolgudan öğelerini göstermeye başlamasını istiyorum. En baştaki arka planı mükemmel bir şekilde görebilir ve görüntüyü/arkaplanı sakladığınız öğeleri kaydettiğinizde.Yatay doldurma başlatıcısı ile başlangıç ​​yastığı

Not: Ne yapmaya çalıştığımı görmek için Play Store'u kontrol edin.

enter image description here

Bu yüzden bu çalışma vardı:

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="#000052" 
android:orientation="vertical" > 

     <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="200dp" 
     android:scaleType="centerCrop" 
     android:src="@drawable/trybg5" 
     android:layout_gravity="left" /> 

       <HorizontalScrollView 
       android:id="@+id/frag_home_gallery_recent_container" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:layout_gravity="right" 
       android:scrollbars="none" 
       android:layout_weight="1" 
       android:paddingBottom="@dimen/horizontalGallery_content_padding" 
       android:paddingTop="@dimen/horizontalGallery_content_padding"> 


       <LinearLayout 
        android:id="@+id/frag_home_gallery_recientes" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" 
        android:paddingLeft="150dp" /> 
      </HorizontalScrollView> 
    </RelativeLayout> 

Benim noktası programlı HorizontalScrollView iç düzenini şişirmek için oradaydı ve o güzel çalıştı. Ama zamanla, RecyclerView'a geçmeye karar verdim ve şimdi beklendiği gibi çalışmıyor.

arka plan görünür

, Recycler sağa yarım ekran başlar, ancak ekranın sol kadar kaydırma olmaz kaydırma zaman, dolgu kuruldu yerde gizlemek sadece edecek ..

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="#000052" 
android:orientation="vertical" > 

    <ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="200dp" 
    android:scaleType="centerCrop" 
    android:src="@drawable/trybg5" 
    android:layout_gravity="left" /> 

      <FrameLayout 
        android:id="@+id/frag_home_gallery_recent_container" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" 
        android:layout_gravity="right" 
        android:scrollbars="none" 
        android:layout_weight="1" 
        android:paddingBottom="@dimen/horizontalGallery_content_padding" 
        android:paddingTop="@dimen/horizontalGallery_content_padding"> 

        <android.support.v7.widget.RecyclerView 
         android:background="@drawable/gallery_bg" 
         android:id="@+id/frag_home_gallery_recientes" 
         android:scrollbars="none" 
         android:paddingLeft="150dp" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         /> 

       </FrameLayout> 
      </RelativeLayout> 

Bu efekti nasıl oluşturabilirim konusunda herhangi bir fikir RecyclerView'da çalışır?

İşte çöp ait ayrıntı verilmiştir:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:clickable="true" 
    android:id="@+id/discoContainer" 
    android:background="@drawable/gallery_bg" 
    android:layout_margin="5dp" 
    android:padding="2dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/containerDisco" 
     android:orientation="vertical"> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
      <ImageView 
       android:id="@+id/logoDisco" 
       android:transitionName="DiscoId" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:scaleType="centerCrop" 
       android:contentDescription="LogoDisco" 
       android:windowSharedElementsUseOverlay="false" /> 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="a 600m tuyos" 
       android:padding="3dp" 
       android:layout_gravity="center_horizontal" 
       android:maxLines="1" 
       android:gravity="center_horizontal" 
       android:alpha="500" 
       android:background="#46000000" 
       android:textColor="@android:color/white"/> 
     </RelativeLayout> 

     <TextView 
      android:id="@+id/logoTexto" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Probando" 
      android:padding="3dp" 
      android:layout_gravity="center_horizontal" 
      android:maxLines="1" 
      android:gravity="center_horizontal" 
      android:layout_alignBottom="@+id/containerDisco" /> 

    </LinearLayout> 


</LinearLayout> 

cevap

9

yerine dolgu kullanmak yerine, genellikle bir ItemDecoration ile etkinin bu tür ulaşmak. Sonra kurarken

public class PaddingItemDecoration extends RecyclerView.ItemDecoration { 
    private final int size; 

    public PaddingItemDecoration(int size) { 
     this.size = size; 
    } 

    @Override 
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 
     super.getItemOffsets(outRect, view, parent, state); 

     // Apply offset only to first item 
     if (parent.getChildAdapterPosition(view) == 0) { 
      outRect.left += size; 
     } 
    } 
} 

senin RecyclerView:

int size = ... // Get the offset that you want 
RecyclerView recyclerView = ... 

recyclerView.addItemDecoration(new PaddingItemDecoration(size)); 
+1

: Yani örneğin

. Çok teşekkür ederim! Bunu bir Android problemi olarak düşünmedim, ancak bir css problemine daha çok benzemeye başladım :) –

+0

İşte RTL desteği ile Kotlin için genişletilmiş bir sürüm: https://gist.github.com/sevar83/1172423f265e1cbb7a04f3d22b12021a – WindRider

+1

hi @ GuillermoLópez Sol tarafta bir düğmem var, aynı davranışı istiyorum. Bunu nasıl başarabiliriz? – Sac

1

Ondan çok daha basittir, RecyclerView zaten bu özelliğe sahiptir: dolgu klip kalmaması sadece RecyclerView XML android:clipToPadding="false" set Eşyalarını kapat. Pürüzsüz Çalışma

<android.support.v7.widget.RecyclerView 
    android:background="@drawable/gallery_bg" 
    android:id="@+id/frag_home_gallery_recientes" 
    android:scrollbars="none" 
    android:paddingLeft="150dp" 
    android:clipToPadding="false 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
İlgili konular