2. 自定义 ItemDecoration 接下来,我们需要创建一个自定义的ItemDecoration类,用于绘制分割线。以下是示例代码: // GridSpacingItemDecoration.javapublicclassGridSpacingItemDecorationextendsRecyclerView.ItemDecoration{privatefinalintspacing;publicGridSpacingItemDecoration(intspacing){this.spacing=spacing;}@Overridepublicvoidge...
设置为childCount-1,这样最后一行末尾处就没有分割线for(inti=0;i<childCount-1;i++){finalViewchild=parent.getChildAt(i);parent.getDecoratedBoundsWithMargins(child,mBounds);finalintbottom=mBounds.bottom+Math.round(child.getTranslationY());finalinttop=bottom-mDivider.getIntrinsicHeight();mDivider.setBou...
添加自定义分割线:可自定义分割线drawable mRecyclerView.addItemDecoration(new RecycleViewDivider( mContext, LinearLayoutManager.VERTICAL, R.drawable.divider_mileage)); 添加自定义分割线:可自定义分割线高度和颜色 mRecyclerView.addItemDecoration(new RecycleViewDivider( mContext, LinearLayoutManager.VERTICAL, 10,...
recycleview 自定义分割线 DividerItemDecorationdivider=newDividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL); divider.setDrawable(ContextCompat.getDrawable(getActivity(),R.drawable.custom_divider)); mRvSort.addItemDecoration(divider); 其中custom_divider是: <?xmlversion="1.0"encoding="utf-8"?> ...
recycleview 自定义分割线 DividerItemDecoration divider = new DividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL);divider.setDrawable(ContextCompat.getDrawable(getActivity(),R.drawable.custom_divider));mRvSort.addItemDecoration(divider);其中custom_divider 是:<?xml version="1.0" encoding="utf-8...
android recycleview 自定义xml分割线 recyclerview添加分割线,>2018年技术周期计划:周期计划-1(2018/1/1-2018/1/7)写在前面以前给RecyclerView加分割线,都是简单的在Item的布局中自己添加想要的效果。这种做法当然是没有什么毛病,不过说到底还是有一些投机取巧。
recycleview 自定义分割线 DividerItemDecoration divider = new DividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL); divider.setDrawable(ContextCompat.getDrawable(getActivity(),R.drawable.custom_divider)); mRvSort.addItemDecoration(divider); ...