11

我想在滑動面板中的Android中重新創建材質設計list: controlsAndroid中遺留材質設計列表的問題

Material Design list with right reveal mockup from the Material Design guidelines

我正在使用的:

我結束了使用支持庫中的部分,但這個特定的應用程序是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

剩下的問題要解決是海拔陰影和除法。

正如你可以在圖像中看到的那樣,列表項的邊上有一些合理的陰影。然而,物品底部沒有高程陰影,因此當物品顯示時,顯示區域上方不會顯示陰影。

第二個問題是分隔符。我有一個沒有圖標/圖像的單個項目列表,所以正確的設計是使用分隔符來表示項目。

但是我不能使用serso/android-linear-layout-manager中的DividerItemDecoration,因爲它沒有集成到滑塊中,並且這會在滑動2個相鄰的項目時發生。 App example with dividers and two revealed list items

有沒有人知道我應該使用任何可繪製,屬性或庫來將這些列表項設置爲具有高程陰影和邊框的材質表?

+1

做你找到這個我有字面上0文檔谷歌的推薦行爲背後許可的答案嗎? – commonSenseCode

+3

我喜歡Material Design和設計指南的全面性,但他們確實需要提供文檔和工具來實施設計指南! –

+1

您是否找到答案?我也想這樣做,沒有下面的答案被標記爲正確= D –

回答

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 /夢詩。XML

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

分頻器

,並以您可能不需要改變分頻器,它可能看起來OK。 否則,請嘗試添加分隔線到視圖本身(頂視圖或自己控制它的可見性)。它可以只是一個高度1DP和寬度match_parentbackgroundColor設置一些暗灰色(或系統分頻器繪製(R.attr.listDivider)查看。

0

對於你的問題的分配部,我會建議尋找到ItemDecorators,你可以添加一個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); 
    } 
} 
} 

和使用addItemDecoration()。 您可以在此頁面上找到完整的教程:

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

0

添加android:clipChildren = "false"到SwipeLayout和RecyclerView。
這裏是我的RecyclerView列表項的佈局:

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

這是當前結果。

enter image description here