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);
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值