2017-06-30 7 views
6

मैं RecyclerView पर विकर्ण कट लेआउट जोड़ रहा हूं, लेकिन मुझे अपेक्षित परिणाम नहीं मिल रहे हैं। मेरा दूसरा दृश्य start with end of first view, and thats obvious। लेकिन मैं क्या चाहता हूं कि प्रत्येक दृश्य join with each-other इस तरह है।गतिशील विकर्ण दृश्य सूची कैसे बनाएं

मेरे आउटपुट:

enter image description here

और इस मैं क्या चाहता है:

enter image description here

CutLayout.class:

public class CutLayout extends FrameLayout { 
    private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 
    private Xfermode pdMode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR); 
    private Path path = new Path(); 

    public CutLayout(Context context) { 
     super(context); 
    } 

    public CutLayout(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public CutLayout(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 

    @TargetApi(Build.VERSION_CODES.LOLLIPOP) 
    public CutLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
     super(context, attrs, defStyleAttr, defStyleRes); 
    } 

    @Override 
    protected void dispatchDraw(Canvas canvas) { 
     int saveCount = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG); 
     super.dispatchDraw(canvas); 

     paint.setXfermode(pdMode); 
     path.reset(); 
     path.moveTo(0, getHeight()); 
     path.lineTo(getWidth(), getHeight()); 
     path.lineTo(getWidth(), getHeight() - TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics())); 
     path.close(); 
     canvas.drawPath(path, paint); 

     canvas.restoreToCount(saveCount); 
     paint.setXfermode(null); 
    } 
} 

item.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context=".SampleActivity"> 

    <com.yarolegovich.slidingrootnav.sample.helper.CutLayout 
     android:layout_width="match_parent" 
     android:layout_height="200dp"> 

     <ImageView 
      android:scaleType="centerCrop" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/homebulding" /> 
    </com.yarolegovich.slidingrootnav.sample.helper.CutLayout> 
</LinearLayout> 
+0

https://stackoverflow.com/questions/39185299/color-overlay-on- की तरह कुछ दे देंगे करने के लिए जोड़ drawable-android –

+0

मैंने इसे पहले से ही देखा है, यह मेरी समस्या नहीं है .. जो मैं चाहता हूं वह गतिशील दृश्य को जोड़ती है .. –

+0

प्रत्येक लिंक मेरे ब्राउज़र में पहले से ही खुला है .., मैं स्थिर रूप से दृश्य को गठबंधन करने में भी सक्षम हूं। लेकिन गतिशील कैसे करें? –

उत्तर

6

बदलें अपनी CutLayout इसलिए की तरह शीर्ष पर एक ही रास्ता है:

public class CutLayout extends FrameLayout { 
    private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 
    private Xfermode pdMode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR); 
    private Path path = new Path(); 

    public CutLayout(Context context) { 
     super(context); 
    } 

    public CutLayout(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public CutLayout(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 

    @TargetApi(Build.VERSION_CODES.LOLLIPOP) 
    public CutLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
     super(context, attrs, defStyleAttr, defStyleRes); 
    } 

    @Override 
    protected void dispatchDraw(Canvas canvas) { 
     int saveCount = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG); 
     super.dispatchDraw(canvas); 

     paint.setXfermode(pdMode); 
     path.reset(); 

     path.moveTo(0, 0); 
     path.lineTo(getWidth(), 0); 
     path.lineTo(0, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics())); 
     path.close(); 
     canvas.drawPath(path, paint); 

     path.reset(); 

     path.moveTo(0, getHeight()); 
     path.lineTo(getWidth(), getHeight()); 
     path.lineTo(getWidth(), getHeight() - TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics())); 
     path.close(); 
     canvas.drawPath(path, paint); 

     canvas.restoreToCount(saveCount); 
     paint.setXfermode(null); 
    } 
} 

फिर तुम सब करने की है के लिए एक आइटम डेकोरेटर बनाने के लिए अपने रीसाइक्लिंग व्यू जो नकारात्मक शीर्ष मार्जिन

public class NegativeTopItemDecorator extends RecyclerView.ItemDecoration{ 
    private final int mTopMargin; 

    public NegativeTopItemDecorator(int topMargin) { 
     this.mTopMargin = topMargin; 
    } 


    @Override 
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 
     outRect.top = mTopMargin; 
    } 
} 
स्वीकार कर सकता है

और यह आपके RecyclerView

int topMargin = - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()); 
NegativeTopItemDecorator itemDecorator = new NegativeTopItemDecorator(topMargin); 
mRecyclerView.addItemDecoration(itemDecorator); 

यह आप निम्नलिखित उत्पादन

sample diagonal cut recycler

+0

मेरे मामले में कार्ड के अंत में हमेशा सफेद स्थान होता है नीचे दाएं। कुछ पता है इसे कैसे हल करना है। –

+0

क्या आपने 'नकारात्मक TopItemDecorator' लागू किया है? – linakis

+0

हां, यही कारण है कि मुझे आपके जैसे आउटपुट मिलते हैं .. लेकिन आखिरी इंडेक्स में छवि भी नग्न जगह छोड़ देती है। –

संबंधित मुद्दे