Recylerview 删除头部分割线

  • @param orientation DividerItemDecoration orientation. Should be {@link #HORIZONTAL} or {@link #VERTICAL}.

*/

public DividerItemDecoration(Context context, int orientation) {

final TypedArray a = context.obtainStyledAttributes(ATTRS);

mDivider = a.getDrawable(0);

if (mDivider == null) {

Log.w(TAG, "@android:attr/listDivider was not set in the theme used for this "

  • “DividerItemDecoration. Please set that attribute all call setDrawable()”);

}

a.recycle();

setOrientation(orientation);

}

/**

  • Sets the orientation for this divider. This should be called if

  • {@link RecyclerView.LayoutManager} changes orientation.

  • @param orientation {@link #HORIZONTAL} or {@link #VERTICAL}

*/

public void setOrientation(int orientation) {

if (orientation != HORIZONTAL && orientation != VERTICAL) {

throw new IllegalArgumentException(

“Invalid orientation. It should be either HORIZONTAL or VERTICAL”);

}

mOrientation = orientation;

}

/**

  • Sets the {@link Drawable} for this divider.

  • @param drawable Drawable that should be used as a divider.

*/

public void setDrawable(@NonNull Drawable drawable) {

if (drawable == null) {

throw new IllegalArgumentException(“Drawable cannot be null.”);

}

mDivider = drawable;

}

@Override

public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {

if (parent.getLayoutManager() == null || mDivider == null) {

return;

}

if (mOrientation == VERTICAL) {

drawVertical(c, parent);

} else {

drawHorizontal(c, parent);

}

}

private void drawVertical(Canvas canvas, RecyclerView parent) {

canvas.save();

final int left;

final int right;

//noinspection AndroidLintNewApi - NewApi lint fails to handle overrides.

if (parent.getClipToPadding()) {

left = parent.getPaddingLeft();

right = parent.getWidth() - parent.getPaddingRight();

canvas.clipRect(left, parent.getPaddingTop(), right,

parent.getHeight() - parent.getPaddingBottom());

} else {

left = 0;

right = parent.getWidth();

}

final int childCount = parent.getChildCount();

for (int i = 0; i < childCount - 1; i++) {

// 获取当前子试图所在的位置

int pos = parent.getChildLayoutPosition(parent.getChildAt(i));

// 跳过这个item不画线

if(i == 0 && pos == 0){

continue;

}

final View child = parent.getChildAt(i);

parent.getDecoratedBoundsWithMargins(child, mBounds);

final int bottom = mBounds.bottom + Math.round(child.getTranslationY());

final int top = bottom - mDivider.getIntrinsicHeight();

mDivider.setBounds(left, top, right, bottom);

mDivider.draw(canvas);

}

canvas.restore();

}

private void drawHorizontal(Canvas canvas, RecyclerView parent) {

canvas.save();

final int top;

final int bottom;

//noinspection AndroidLintNewApi - NewApi lint fails to handle overrides.

if (parent.getClipToPadding()) {

top = parent.getPaddingTop();

bottom = parent.getHeight() - parent.getPaddingBottom();

canvas.clipRect(parent.getPaddingLeft(), top,

parent.getWidth() - parent.getPaddingRight(), bottom);

} else {

top = 0;

bottom = parent.getHeight();

}

final int childCount = parent.getChildCount();

for (int i = 0; i < childCount; i++) {

final View child = parent.getChildAt(i);

parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);

final int right = mBounds.right + Math.round(child.getTranslationX());

最后,面试前该准备哪些资源复习?

其实客户端开发的知识点就那么多,面试问来问去还是那么点东西。所以面试没有其他的诀窍,只看你对这些知识点准备的充分程度。so,出去面试时先看看自己复习到了哪个阶段就好。

这里再分享一下我面试期间的复习路线:(以下体系的复习资料是我从各路大佬收集整理好的)

《Android开发七大模块核心知识笔记》

面试字节两轮后被完虐,字节面试官给你的技术面试指南,请查收

面试字节两轮后被完虐,字节面试官给你的技术面试指南,请查收

《960全网最全Android开发笔记》

面试字节两轮后被完虐,字节面试官给你的技术面试指南,请查收

《379页Android开发面试宝典》

历时半年,我们整理了这份市面上最全面的安卓面试题解析大全
包含了腾讯、百度、小米、阿里、乐视、美团、58、猎豹、360、新浪、搜狐等一线互联网公司面试被问到的题目。熟悉本文中列出的知识点会大大增加通过前两轮技术面试的几率。

《507页Android开发相关源码解析》

只要是程序员,不管是Java还是Android,如果不去阅读源码,只看API文档,那就只是停留于皮毛,这对我们知识体系的建立和完备以及实战技术的提升都是不利的。

真正最能锻炼能力的便是直接去阅读源码,不仅限于阅读各大系统源码,还包括各种优秀的开源库。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!
关源码解析》**

只要是程序员,不管是Java还是Android,如果不去阅读源码,只看API文档,那就只是停留于皮毛,这对我们知识体系的建立和完备以及实战技术的提升都是不利的。

真正最能锻炼能力的便是直接去阅读源码,不仅限于阅读各大系统源码,还包括各种优秀的开源库。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!

  • 30
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值