private void drawHorizontal(Canvas c, RecyclerView parent, State state) {
int childCount = parent.getChildCount() - 1;
int left = 0;
int top = parent.getPaddingTop();
int right = 0;
int bottom = parent.getHeight() - parent.getPaddingBottom();
for (int i = 0; i < childCount; i++) {
View view = parent.getChildAt(i);
RecyclerView.LayoutParams params = (LayoutParams) view.getLayoutParams(); //考虑,padding
left = view.getRight();
right = left + divider.getIntrinsicHeight(); //我们在自定义drawable的是是,写死了高度,所以只能用高度
divider.setBounds(left, top, right, bottom);
divider.draw(c);
}
}
/**
* 思路:就是获取每个item,计算divider的left,top,right,bottom
*/
private void drawVertical(Canvas c, RecyclerView parent, State state) {
int childCount = parent.getChildCount() - 1;
int left = parent.getPaddingLeft();
int top = 0;
int right = parent.getWidth() - parent.getPaddingRight(); //考虑右边的padding
int bottom = 0;
for (int i = 0; i < childCount; i++) { //不绘制最后一个条目的分割线
View view = parent.getChildAt(i);
RecyclerView.LayoutParams params = (LayoutParams) view.getLayoutParams(); //考虑,padding
top = view.getBottom() + params.topMargin; //就是当前view底部到顶部的距离
bottom = top + divider.getIntrinsicHeight() - params.bottomMargin; //就是top+divider高度
divider.setBounds(left, top, right, bottom);
divider.draw(c);
}
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state) {
int childAdapterPosition = parent.getChildAdapterPosition(view);
int lastCount = parent.getAdapter().getItemCount() - 1;
//如果当前条目与是最后一个条目,就不设置divider padding
if (childAdapterPosition == lastCount) {
outRect.set(0, 0, 0, 0);
return;
}
Log.d("TAG", childAdapterPosition + "," + lastCount);
if (orientation == LinearLayoutCompat.HORIZONTAL) {
outRect.set(0, 0, divider.getIntrinsicHeight(), 0); //0,0,30,0,设置宽度
} else {
outRect.set(0, 0, 0, divider.getIntrinsicHeight()); //0,0,0,30,设置高度
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有