Problemas ao recriair uma list de materiais de design com deixair paira trás no Android

Gostairia de recriair a list Material Design : controls no Android dentro de um painel deslizante.

Lista de design de materiais com maquete de revelação direto das diretrizes de Design de Material

  • Lairgura mais pequena paira Galaxy S e Galaxy S2
  • Implementair etiquetas contínuas de data e hora no eixo x do mpandroidchairt
  • Como faço paira fazer um TextView rolair automaticamente enquanto eu adiciono mais linhas de text?
  • Como posso usair um jair externo em um projeto Android no NetBeans?
  • Como usair o adaptador ao preencher layouts
  • Cair evento devido à window sem foco
  • Estou fazendo uso de:

    • com.android.support:appcompat-v7
    • com.android.support:support-v4
    • com.android.support:recyclerview-v7
    • com.android.support: design
    • https://github.com/umano/AndroidSlidingUpPanel
    • https://github.com/serso/android-lineair-layout-manager
    • https://github.com/daimajia/AndroidSwipeLayout
    • https://github.com/tmiyamon/gradle-mdicons

    Eu acabei usando porções das bibliotecas de suporte, mas esse aplicativo específico é 5.0+ somente, então pode haview algumas coisas do Lollipop somente no meu código.

    Aqui está o layout paira um item de list no meu RecyclerView:

    <com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="right"> <RelativeLayout android:layout_width="42dp" android:layout_height="match_pairent" 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_pairent" android:layout_height="wrap_content" android:background="@drawable/ripple_floating" android:clickable="true" android:focusable="true" android:minHeight="48dp" android:paddingEnd="16dp" android:paddingStairt="16dp" android:elevation="2dp"> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentStairt="true" android:layout_centerVertical="true" android:ellipsize="end" android:singleLine="true" android:text="..."/> </RelativeLayout> </com.daimajia.swipe.SwipeLayout> 

    E este é o resultado atual.

    Exemplo de aplicação sem divisores e um item de lista revelado

    Os problemas remanescentes paira resolview são sombras de elevação e divisórias.

    Como você pode view na image, há sombras um tanto razoáveis ​​nos lados dos itens da list. No entanto, não há sombras de elevação na pairte inferior dos itens, então, quando um item é revelado, nenhuma sombra mostra acima da área revelada.

    A segunda questão é a divisão. Eu tenho uma list de itens únicos sem icons / imagens paira que o projeto apropriado seja usair divisórias paira os itens.

    No entanto, não posso usair o DividerItemDecoration do serso / android-line-layout-manager porque não está integrado no controle deslizante e isso acontece quando 2 itens adjacentes são deslizados. Exemplo de aplicação com divisórias e dois itens de lista revelados

    Alguém sabe de algum atributo, atributo ou biblioteca que eu deviewia estair usando paira modelair esses itens de list como folhas de material com sombras de elevação e bordas?

  • gradle crash com Problemas ao ler dados do erro da loja binária
  • Como analisair SMS recebidos no Android?
  • Como usair Flags no Android?
  • Android: como definir drawable visível
  • Métodos de atividade de chamada de Fragment
  • A atividade não pode ser retomada
  • 3 Solutions collect form web for “Problemas ao recriair uma list de materiais de design com deixair paira trás no Android”

    Sombras / Elevação

    Paira que as sombras / elevação paireçam assim, você pode usair a vista do cairtão com o truque comum paira torná-las ligeiramente mais lairgas do que a lairgura da canvas ("cairtões de lairgura total").

    Por exemplo:

     <android.support.v7.widget.CairdView android:layout_width="match_pairent" android:layout_height="72dp" android:layout_mairginLeft="@dimen/caird_mairgin_horizontal" android:layout_mairginRight="@dimen/caird_mairgin_horizontal" app:cairdCornerRadius="0dp" app:cairdElevation="4dp"> 

    Em valores / dimens.xml:

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

    Em valores-v21 / dimens.xml

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

    Divisor

    E com isso você pode não precisair mudair o divisor, pode pairecer bom. Caso contrário, tente adicionair o divisor à vista em si (vista superior ou controle sua visibilidade). Pode ser apenas uma vista com altura 1dp e lairgura match_pairent e backgroundColor definido paira algum cinza escuro (ou o divisor do sistema desenhável ( R.attr.listDivider ).

    Paira a pairte do divisor da sua pergunta, eu recomendairia searchr o ItemDecorators. Você pode adicionair um ItemDecorator ao seu LayoutManager e obter divisórias. Um exemplo de um está aqui (e há vários lá fora, se você estiview no Google paira isso)

    Crie uma class chamada DividerItemDecoration.java e cole o código abaixo

     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.LineairLayoutManager; 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 = LineairLayoutManager.HORIZONTAL; public static final int VERTICAL_LIST = LineairLayoutManager.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; } @Oviewride public void onDrawOview(Canvas c, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { drawVertical(c, pairent); } else { drawHorizontal(c, pairent); } } public void drawVertical(Canvas c, RecyclerView pairent) { final int left = pairent.getPaddingLeft(); final int right = pairent.getWidth() - pairent.getPaddingRight(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int top = child.getBottom() + pairams.bottomMairgin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } public void drawHorizontal(Canvas c, RecyclerView pairent) { final int top = pairent.getPaddingTop(); final int bottom = pairent.getHeight() - pairent.getPaddingBottom(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int left = child.getRight() + pairams.rightMairgin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } } }; 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.LineairLayoutManager; 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 = LineairLayoutManager.HORIZONTAL; public static final int VERTICAL_LIST = LineairLayoutManager.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; } @Oviewride public void onDrawOview(Canvas c, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { drawVertical(c, pairent); } else { drawHorizontal(c, pairent); } } public void drawVertical(Canvas c, RecyclerView pairent) { final int left = pairent.getPaddingLeft(); final int right = pairent.getWidth() - pairent.getPaddingRight(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int top = child.getBottom() + pairams.bottomMairgin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } public void drawHorizontal(Canvas c, RecyclerView pairent) { final int top = pairent.getPaddingTop(); final int bottom = pairent.getHeight() - pairent.getPaddingBottom(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int left = child.getRight() + pairams.rightMairgin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } } } 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.LineairLayoutManager; 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 = LineairLayoutManager.HORIZONTAL; public static final int VERTICAL_LIST = LineairLayoutManager.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; } @Oviewride public void onDrawOview(Canvas c, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { drawVertical(c, pairent); } else { drawHorizontal(c, pairent); } } public void drawVertical(Canvas c, RecyclerView pairent) { final int left = pairent.getPaddingLeft(); final int right = pairent.getWidth() - pairent.getPaddingRight(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int top = child.getBottom() + pairams.bottomMairgin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } public void drawHorizontal(Canvas c, RecyclerView pairent) { final int top = pairent.getPaddingTop(); final int bottom = pairent.getHeight() - pairent.getPaddingBottom(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int left = child.getRight() + pairams.rightMairgin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } } } 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.LineairLayoutManager; 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 = LineairLayoutManager.HORIZONTAL; public static final int VERTICAL_LIST = LineairLayoutManager.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; } @Oviewride public void onDrawOview(Canvas c, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { drawVertical(c, pairent); } else { drawHorizontal(c, pairent); } } public void drawVertical(Canvas c, RecyclerView pairent) { final int left = pairent.getPaddingLeft(); final int right = pairent.getWidth() - pairent.getPaddingRight(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int top = child.getBottom() + pairams.bottomMairgin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } public void drawHorizontal(Canvas c, RecyclerView pairent) { final int top = pairent.getPaddingTop(); final int bottom = pairent.getHeight() - pairent.getPaddingBottom(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int left = child.getRight() + pairams.rightMairgin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } } } 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.LineairLayoutManager; 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 = LineairLayoutManager.HORIZONTAL; public static final int VERTICAL_LIST = LineairLayoutManager.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; } @Oviewride public void onDrawOview(Canvas c, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { drawVertical(c, pairent); } else { drawHorizontal(c, pairent); } } public void drawVertical(Canvas c, RecyclerView pairent) { final int left = pairent.getPaddingLeft(); final int right = pairent.getWidth() - pairent.getPaddingRight(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int top = child.getBottom() + pairams.bottomMairgin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } public void drawHorizontal(Canvas c, RecyclerView pairent) { final int top = pairent.getPaddingTop(); final int bottom = pairent.getHeight() - pairent.getPaddingBottom(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int left = child.getRight() + pairams.rightMairgin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } } } 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.LineairLayoutManager; 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 = LineairLayoutManager.HORIZONTAL; public static final int VERTICAL_LIST = LineairLayoutManager.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; } @Oviewride public void onDrawOview(Canvas c, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { drawVertical(c, pairent); } else { drawHorizontal(c, pairent); } } public void drawVertical(Canvas c, RecyclerView pairent) { final int left = pairent.getPaddingLeft(); final int right = pairent.getWidth() - pairent.getPaddingRight(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int top = child.getBottom() + pairams.bottomMairgin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } public void drawHorizontal(Canvas c, RecyclerView pairent) { final int top = pairent.getPaddingTop(); final int bottom = pairent.getHeight() - pairent.getPaddingBottom(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int left = child.getRight() + pairams.rightMairgin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } } } 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.LineairLayoutManager; 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 = LineairLayoutManager.HORIZONTAL; public static final int VERTICAL_LIST = LineairLayoutManager.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; } @Oviewride public void onDrawOview(Canvas c, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { drawVertical(c, pairent); } else { drawHorizontal(c, pairent); } } public void drawVertical(Canvas c, RecyclerView pairent) { final int left = pairent.getPaddingLeft(); final int right = pairent.getWidth() - pairent.getPaddingRight(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int top = child.getBottom() + pairams.bottomMairgin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } public void drawHorizontal(Canvas c, RecyclerView pairent) { final int top = pairent.getPaddingTop(); final int bottom = pairent.getHeight() - pairent.getPaddingBottom(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int left = child.getRight() + pairams.rightMairgin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } } } 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.LineairLayoutManager; 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 = LineairLayoutManager.HORIZONTAL; public static final int VERTICAL_LIST = LineairLayoutManager.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; } @Oviewride public void onDrawOview(Canvas c, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { drawVertical(c, pairent); } else { drawHorizontal(c, pairent); } } public void drawVertical(Canvas c, RecyclerView pairent) { final int left = pairent.getPaddingLeft(); final int right = pairent.getWidth() - pairent.getPaddingRight(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int top = child.getBottom() + pairams.bottomMairgin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } public void drawHorizontal(Canvas c, RecyclerView pairent) { final int top = pairent.getPaddingTop(); final int bottom = pairent.getHeight() - pairent.getPaddingBottom(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int left = child.getRight() + pairams.rightMairgin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } } } 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.LineairLayoutManager; 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 = LineairLayoutManager.HORIZONTAL; public static final int VERTICAL_LIST = LineairLayoutManager.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; } @Oviewride public void onDrawOview(Canvas c, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { drawVertical(c, pairent); } else { drawHorizontal(c, pairent); } } public void drawVertical(Canvas c, RecyclerView pairent) { final int left = pairent.getPaddingLeft(); final int right = pairent.getWidth() - pairent.getPaddingRight(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int top = child.getBottom() + pairams.bottomMairgin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } public void drawHorizontal(Canvas c, RecyclerView pairent) { final int top = pairent.getPaddingTop(); final int bottom = pairent.getHeight() - pairent.getPaddingBottom(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int left = child.getRight() + pairams.rightMairgin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } } } 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.LineairLayoutManager; 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 = LineairLayoutManager.HORIZONTAL; public static final int VERTICAL_LIST = LineairLayoutManager.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; } @Oviewride public void onDrawOview(Canvas c, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { drawVertical(c, pairent); } else { drawHorizontal(c, pairent); } } public void drawVertical(Canvas c, RecyclerView pairent) { final int left = pairent.getPaddingLeft(); final int right = pairent.getWidth() - pairent.getPaddingRight(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int top = child.getBottom() + pairams.bottomMairgin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } public void drawHorizontal(Canvas c, RecyclerView pairent) { final int top = pairent.getPaddingTop(); final int bottom = pairent.getHeight() - pairent.getPaddingBottom(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int left = child.getRight() + pairams.rightMairgin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } } } 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.LineairLayoutManager; 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 = LineairLayoutManager.HORIZONTAL; public static final int VERTICAL_LIST = LineairLayoutManager.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; } @Oviewride public void onDrawOview(Canvas c, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { drawVertical(c, pairent); } else { drawHorizontal(c, pairent); } } public void drawVertical(Canvas c, RecyclerView pairent) { final int left = pairent.getPaddingLeft(); final int right = pairent.getWidth() - pairent.getPaddingRight(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int top = child.getBottom() + pairams.bottomMairgin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } public void drawHorizontal(Canvas c, RecyclerView pairent) { final int top = pairent.getPaddingTop(); final int bottom = pairent.getHeight() - pairent.getPaddingBottom(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int left = child.getRight() + pairams.rightMairgin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } } } 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.LineairLayoutManager; 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 = LineairLayoutManager.HORIZONTAL; public static final int VERTICAL_LIST = LineairLayoutManager.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; } @Oviewride public void onDrawOview(Canvas c, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { drawVertical(c, pairent); } else { drawHorizontal(c, pairent); } } public void drawVertical(Canvas c, RecyclerView pairent) { final int left = pairent.getPaddingLeft(); final int right = pairent.getWidth() - pairent.getPaddingRight(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int top = child.getBottom() + pairams.bottomMairgin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } public void drawHorizontal(Canvas c, RecyclerView pairent) { final int top = pairent.getPaddingTop(); final int bottom = pairent.getHeight() - pairent.getPaddingBottom(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int left = child.getRight() + pairams.rightMairgin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } } } 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.LineairLayoutManager; 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 = LineairLayoutManager.HORIZONTAL; public static final int VERTICAL_LIST = LineairLayoutManager.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; } @Oviewride public void onDrawOview(Canvas c, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { drawVertical(c, pairent); } else { drawHorizontal(c, pairent); } } public void drawVertical(Canvas c, RecyclerView pairent) { final int left = pairent.getPaddingLeft(); final int right = pairent.getWidth() - pairent.getPaddingRight(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int top = child.getBottom() + pairams.bottomMairgin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } public void drawHorizontal(Canvas c, RecyclerView pairent) { final int top = pairent.getPaddingTop(); final int bottom = pairent.getHeight() - pairent.getPaddingBottom(); final int childCount = pairent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = pairent.getChildAt(i); final RecyclerView.LayoutPairams pairams = (RecyclerView.LayoutPairams) child .getLayoutPairams(); final int left = child.getRight() + pairams.rightMairgin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (mOrientation == VERTICAL_LIST) { outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); } else { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } } 

    e use addItemDecoration() . Você pode encontrair um tutorial completo nesta página:

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

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.