2015-12-15 17 views
5

के साथ देखें तो मेरे पास पृष्ठभूमि के रूप में एक छवि दृश्य है और इसके शीर्ष पर एक क्षैतिज रीसाइक्लर व्यू है, यह बात यह है कि मैं चाहता हूं कि रीसाइक्लर व्यू को स्क्रीन के आधा पैडिंग से बाईं ओर अपने आइटम दिखाना शुरू करें ताकि आप शुरुआत में पूरी तरह से पृष्ठभूमि देख सकते हैं और जब आप आइटम स्क्रॉल करते हैं तो आप छवि/पृष्ठभूमि को छुपाएंगे।क्षैतिज पुनर्चक्रण प्रारंभिक पैडिंग

नोट: यह देखने के लिए Play Store की जांच करें कि मैं क्या करने की कोशिश कर रहा हूं।

enter image description here

तो मैं इस काम के लिए किया था:

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

मेरे मतलब नहीं प्रोग्राम के रूप में HorizontalScrollView अंदर लेआउट को बढ़ाने के लिए था, और यह अच्छी तरह से काम किया। लेकिन उस समय के साथ, मैंने रीसाइक्लिंग व्यू में माइग्रेट करने का निर्णय लिया और अब उम्मीद के अनुसार काम नहीं कर रहा है।

पृष्ठभूमि प्रकट होता है, रेमंड सही करने के लिए आधी स्क्रीन शुरू होता है, लेकिन जब स्क्रॉल यह स्क्रीन के बाईं तक स्क्रॉल नहीं होंगे, इसे छिपाने सिर्फ होगा जहाँ भी गद्दी स्थापित किया गया था ..

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

रीसाइक्लर व्यू में मैं इस प्रभाव को कैसे काम कर सकता हूं इसका कोई विचार?

यहाँ recycler से विवरण दिया गया है:

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

उत्तर

9

इसके बजाय गद्दी का उपयोग कर के, मैं आमतौर पर प्रभाव इस तरह की एक ItemDecoration साथ हासिल करते हैं।

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

फिर जब आप की स्थापना अपने RecyclerView:

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

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

चिकनी कार्य करना। बहुत बहुत धन्यवाद! मैंने इसे एंड्रॉइड समस्या के रूप में नहीं सोचा था, लेकिन सीएसएस समस्या की अधिक संभावना है :) –

+0

यहां आरटीएल समर्थन के साथ कोटलिन के लिए एक विस्तारित संस्करण है: https://gist.github.com/sevar83/1172423f265e1cbb7a04f3dicies12021a – WindRider

+1

हाय @ गिलर्मोलोपेज़ , मैं वही व्यवहार चाहता हूं सिवाय इसके कि मेरे पास बाईं तरफ एक बटन है। हम इसे कैसे प्राप्त कर सकते हैं? – Sac

1

ऐसा नहीं है कि तुलना में बहुत सरल है, RecyclerView पहले से ही है कि सुविधा है: बस, RecyclerView एक्सएमएल को android:clipToPadding="false" सेट ताकि गद्दी क्लिप नहीं है अपने सामान बंद करो।

तो अपने उदाहरण के लिए

:

<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" /> 
संबंधित मुद्दे