11

में पीछे छोड़कर सामग्री डिज़ाइन सूचियों को दोबारा बनाने के मुद्दे मैं एक स्लाइडिंग पैनल के अंदर एंड्रॉइड में सामग्री डिजाइन list: controls को फिर से बनाना चाहता हूं।एंड्रॉइड

मैं समर्थन लाइब्रेरी के कुछ भागों का उपयोग कर समाप्त हो गया है, लेकिन इस विशिष्ट एप्लिकेशन 5.0+ केवल इसलिए मेरे कोड में कुछ लॉलीपॉप-केवल सामान हो सकता है।

यहाँ मेरी RecyclerView में किसी सूची आइटम के लिए लेआउट है:

<com.daimajia.swipe.SwipeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right"> 
    <RelativeLayout 
     android:layout_width="42dp" 
     android:layout_height="match_parent" 
     android:background="?android:selectableItemBackground" 
     android:clickable="true" 
     android:focusable="true"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true" 
      android:src="@drawable/ic_delete_black_24dp"/> 

    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/surfaceView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/ripple_floating" 
     android:clickable="true" 
     android:focusable="true" 
     android:minHeight="48dp" 
     android:paddingEnd="16dp" 
     android:paddingStart="16dp" 
     android:elevation="2dp"> 

     <TextView 
      android:id="@+id/name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentStart="true" 
      android:layout_centerVertical="true" 
      android:ellipsize="end" 
      android:singleLine="true" 
      android:text="..."/> 

    </RelativeLayout> 
</com.daimajia.swipe.SwipeLayout> 

और यह वर्तमान परिणाम है।

App example with no dividers and one revealed list item

हल करने के लिए शेष समस्याओं ऊंचाई छाया और विभाजक हैं।

जैसा कि आप छवि में देख सकते हैं सूची आइटम के किनारों पर कुछ हद तक उचित छाया हैं। हालांकि वस्तुओं के निचले हिस्से में कोई ऊंचाई छाया नहीं है, इसलिए जब कोई आइटम प्रकट होता है तो प्रकट क्षेत्र के ऊपर कोई छाया दिखाई नहीं देती है।

दूसरा मुद्दा डिवाइडर है। मेरे पास एक सिंगल-आइटम सूची है जिसमें कोई आइकन/छवियां नहीं हैं, इसलिए उचित डिज़ाइन आइटम के लिए डिवाइडर का उपयोग करना है।

हालांकि मैं sidero/android-linear-layout-manager से DividerItemDecoration का उपयोग नहीं कर सकता क्योंकि यह स्लाइडर में एकीकृत नहीं है और ऐसा तब होता है जब 2 आसन्न आइटम स्लिप होते हैं। App example with dividers and two revealed list items

क्या किसी को भी किसी भी ड्रायबल, विशेषता, या लाइब्रेरी के बारे में पता है, मुझे इन सूची आइटमों को ऊंचाई छाया और सीमाओं के साथ सामग्री शीट के रूप में स्टाइल करने के लिए उपयोग करना चाहिए?

+1

आप इस मैं व्यवहार के पीछे गूगल की सिफारिश की छुट्टी के लिए सचमुच 0 दस्तावेज के लिए एक जवाब मिल गया था? – commonSenseCode

+3

मुझे मटेरियल डिज़ाइन और डिज़ाइन दिशानिर्देशों की पूर्णता पसंद है, लेकिन उन्हें डिज़ाइन दिशानिर्देशों को लागू करने के लिए वास्तव में दस्तावेज़ और टूल प्रदान करने की आवश्यकता है! –

+1

क्या आपको कोई जवाब मिला? मैं यह भी करना चाहता हूं और नीचे दिए गए उत्तरों में से कोई भी सही = डी के रूप में टैग नहीं किया गया है –

उत्तर

0

छाया/ऊंचाई

छाया/ऊंचाई की तरह आप सामान्य चाल के साथ कार्ड दृश्य का उपयोग कर सकते हैं कि उन्हें स्क्रीन की चौड़ाई की तुलना में थोड़ा व्यापक बनाने के लिए देखने के लिए के लिए ("पूरी चौड़ाई कार्ड")।

उदाहरण के लिए:

<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="72dp" 
    android:layout_marginLeft="@dimen/card_margin_horizontal" 
    android:layout_marginRight="@dimen/card_margin_horizontal" 
    app:cardCornerRadius="0dp" 
    app:cardElevation="4dp"> 

मूल्यों/dimens.xml में:

<dimen name="card_margin_horizontal">-3dp</dimen> 

मान-V21/dimens में।एक्सएमएल

<dimen name="card_margin_horizontal">0dp</dimen> 

डिवाइडर

और उसके साथ आपको विभक्त बदलने की जरूरत नहीं हो सकता है, यह ठीक लग सकता है। अन्यथा स्वयं को दृश्य में विभाजक जोड़ने का प्रयास करें (शीर्ष दृश्य या इसे स्वयं दृश्यता को नियंत्रित करें)। यह ऊंचाई 1DP और चौड़ाई match_parent और कुछ गहरे भूरे रंग के backgroundColor सेट (या प्रणाली विभक्त drawable (R.attr.listDivider) के साथ सिर्फ एक दृश्य हो सकता है।

0

अपने प्रश्न का विभक्त हिस्सा मैं ItemDecorators में देख सिफारिश करेंगे के लिए। आप जोड़ सकते हैं अपने LayoutManager के लिए एक ItemDecorator और विभाजक मिलता है। एक का एक उदाहरण here है (और वहाँ कई करता है, तो आप इसके लिए गूगल देखते हैं)

0

DividerItemDecoration.java नाम के एक वर्ग बनाएं और नीचे दिए गए कोड

import android.content.Context; 
import android.content.res.TypedArray; 
import android.graphics.Canvas; 
import android.graphics.Rect; 
import android.graphics.drawable.Drawable; 
import android.support.v7.widget.LinearLayoutManager; 
import android.support.v7.widget.RecyclerView; 
import android.view.View; 


public class DividerItemDecoration extends RecyclerView.ItemDecoration { 

private static final int[] ATTRS = new int[]{ 
     android.R.attr.listDivider 
}; 

public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL; 

public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL; 

private Drawable mDivider; 

private int mOrientation; 

public DividerItemDecoration(Context context, int orientation) { 
    final TypedArray a = context.obtainStyledAttributes(ATTRS); 
    mDivider = a.getDrawable(0); 
    a.recycle(); 
    setOrientation(orientation); 
} 

public void setOrientation(int orientation) { 
    if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) { 
     throw new IllegalArgumentException("invalid orientation"); 
    } 
    mOrientation = orientation; 
} 

@Override 
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { 
    if (mOrientation == VERTICAL_LIST) { 
     drawVertical(c, parent); 
    } else { 
     drawHorizontal(c, parent); 
    } 
} 

public void drawVertical(Canvas c, RecyclerView parent) { 
    final int left = parent.getPaddingLeft(); 
    final int right = parent.getWidth() - parent.getPaddingRight(); 

    final int childCount = parent.getChildCount(); 
    for (int i = 0; i < childCount; i++) { 
     final View child = parent.getChildAt(i); 
     final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 
       .getLayoutParams(); 
     final int top = child.getBottom() + params.bottomMargin; 
     final int bottom = top + mDivider.getIntrinsicHeight(); 
     mDivider.setBounds(left, top, right, bottom); 
     mDivider.draw(c); 
    } 
} 

public void drawHorizontal(Canvas c, RecyclerView parent) { 
    final int top = parent.getPaddingTop(); 
    final int bottom = parent.getHeight() - parent.getPaddingBottom(); 

    final int childCount = parent.getChildCount(); 
    for (int i = 0; i < childCount; i++) { 
     final View child = parent.getChildAt(i); 
     final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 
       .getLayoutParams(); 
     final int left = child.getRight() + params.rightMargin; 
     final int right = left + mDivider.getIntrinsicHeight(); 
     mDivider.setBounds(left, top, right, bottom); 
     mDivider.draw(c); 
    } 
} 

@Override 
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 
    if (mOrientation == VERTICAL_LIST) { 
     outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); 
    } else { 
     outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); 
    } 
} 
} 

औरका प्रयोग करें। तो आप इस पेज पर पूर्ण ट्यूटोरियल पा सकते हैं:

http://www.androidhive.info/2016/01/android-working-with-recycler-view/

0

SwipeLayout और RecyclerView को android:clipChildren = "false" जोड़ें।

<com.daimajia.swipe.SwipeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/swipe_layout" 
    android:layout_width="match_parent" 
    android:layout_height="80dp" 
    android:layout_marginBottom="1px" 
    android:clipChildren="false" 
    app:show_mode="lay_down"> 

    <ImageView 
     android:layout_width="60dp" 
     android:layout_height="match_parent" 
     android:scaleType="center" 
     android:src="@drawable/ic_settings_black_24dp"/> 

    <FrameLayout 
     android:id="@+id/surface_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/white" 
     android:elevation="2dp"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="@string/app_name"/> 
    </FrameLayout> 
</com.daimajia.swipe.SwipeLayout> 

यहाँ लेआउट मेरी RecyclerView है:

<android.support.v7.widget.RecyclerView 
     android:id="@+id/rv" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorBackground" 
     android:clipChildren="false" 
     android:scrollbarStyle="outsideOverlay" 
     android:scrollbars="vertical"/> 

और यह वर्तमान परिणाम है
यहाँ मेरी RecyclerView में किसी सूची आइटम के लिए लेआउट है।

enter image description here