Android应用开发—RecyclerView绘制蒙层

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/voidreturn/article/details/77718470

背景:如何在跨越两个或两个以上的item绘制一个view,该view需要跟随recyclerView的滑动而整体移动。

 @Override
    public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
        super.onDrawOver(c, parent, state);

        final View child = parent.getChildAt(1);
        if (child != null) {
            final int left = child.getLeft();
            final int right = child.getRight();
            final int top = child.getTop();
            final int bottom = child.getBottom();

            int rightV = (right - left) / 6;
            int leftV = (right - rightV) - VAUtils.dip2px(mContext, 225);
            int topV = bottom - VAUtils.dip2px(mContext, 16);
            int bottomV = topV + VAUtils.dip2px(mContext, 82);

            ViewGroup.MarginLayoutParams margin = new ViewGroup.MarginLayoutParams(mImageView.getLayoutParams());
            margin.setMargins(leftV, topV, rightV, bottomV);
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(margin);

            mImageView.setLayoutParams(layoutParams);

            if (!imageClicked) {
                mImageView.setVisibility(View.VISIBLE);
            }


            //画笔
            final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
            //圆心 x 坐标
            final float x = parent.getWidth() / 2 + left;
            ////圆心 y 坐标
            final float y = 100 + top;
            //半径
            final float radius = 100;
            //渐变着色器 坐标随意设置的
            final LinearGradient shader = new LinearGradient(x-50, 0, x+100, 200, Color.RED, Color.YELLOW, Shader.TileMode.REPEAT);
            paint.setShader(shader);
            //绘制圆
            c.drawCircle(x, y, radius, paint);

        }
    }
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDrawOver(c, parent, state);
    //画笔
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    //圆心 x 坐标
    final float x = parent.getWidth() / 2;
    ////圆心 y 坐标
    final float y = 100;
    //半径
    final float radius = 100;
    //渐变着色器 坐标随意设置的
    final LinearGradient shader = new LinearGradient(x-50, 0, x+100, 200, Color.RED, Color.YELLOW, Shader.TileMode.REPEAT);
    paint.setShader(shader);
    //绘制圆
    c.drawCircle(x, y, radius, paint);
}
上一篇:python学习(二)百度爬虫0.1


下一篇:java打印调用堆栈的方式