Skip to content

Latest commit

 

History

History
43 lines (33 loc) · 1.19 KB

README.md

File metadata and controls

43 lines (33 loc) · 1.19 KB

MaskImageView

可添加遮罩的ImageView,可在外部通过canvas绘制遮罩,内置椭圆和圆角矩形两种遮罩,可选择Xfermode或BitmapShader绘制遮罩

round

round

使用

  • 直接在布局中使用
<com.runing.view.MaskImageView
    android:id="@+id/miv_content"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:src="@drawable/img0"
    app:center="true"
    app:mask_mode="xfermode"
    app:mask_shape="circle" />
  • 在代码中设置自定义遮罩
mMaskImageView.setDrawMask(new MaskImageView.DrawMask() {
    Path mPath = new Path();

    @Override
    public void onDrawMask(Canvas canvas, Paint paint, @Px int viewW, @Px int viewH) {
        mPath.reset();
        mPath.moveTo(viewW / 4, 0);
        mPath.lineTo(viewW / 4 * 3, 0);
        mPath.lineTo(viewW, viewH);
        mPath.lineTo(0, viewH);
        mPath.close();
        canvas.drawPath(mPath, paint);
    }
});

round