首页 > 其他 > 详细

ItemDecoration自定义宽度和颜色

时间:2017-11-01 15:29:07      阅读:508      评论:0      收藏:0      [点我收藏+]
/**
* 垂直布局分割线绘制
* @param c
* @param parent
*/
private 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+Math.round(ViewCompat.getTranslationZ(child));
final int bottom=top+drawable.getIntrinsicHeight();
drawable.setBounds(left,top+2,right,bottom);//宽度调节
drawable.setColorFilter(context.getResources().getColor(R.color.colorAccent), PorterDuff.Mode.XOR);//Mode选择不对无法正常显示选择的颜色
drawable.draw(c);


如代码所示,宽度其实就是控制top和bottom的距离,加减就可以了,很简单。
颜色就是drawable设置setColorFilter设置颜色和Mode,注意有的Mode颜色显示不正常

ItemDecoration自定义宽度和颜色

原文:http://www.cnblogs.com/a1070022846/p/7766654.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!