美文网首页
android kotlin 自定义随手动的小球

android kotlin 自定义随手动的小球

作者: lhybxs | 来源:发表于2018-05-04 10:32 被阅读0次

    初始化一支 画笔Paint

    init {

    paint.color = Color.RED;//画笔颜色

    paint.style = Paint.Style.FILL;//画笔实心  即画实心圆

    }

    在values目录下新建一个 attrs.xml 存放自定义属性

    创建带两个参数的 构造参数  利用 AttributeSet获取自定义的属性:

    constructor(context: Context, attributeSet: AttributeSet) :this(context) {

    var a:TypedArray=context.obtainStyledAttributes(attributeSet,R.styleable.MyBall_attrs);

    mWidth=a.getDimension(R.styleable.MyBall_attrs_width,100f ).toInt();

    mHight=a.getDimension(R.styleable.MyBall_attrs_height,100f).toInt()

    moveX=mWidth/2f;//moveX 圆心的移动坐标X

        moveY=mHight/2f;//moveY 圆心的移动坐标Y

        mRadius=mWidth/2f;//圆的半径

    }

    调用 onDraw()绘制,onTouchEvent()监听移动 在布局文件中的使用     

    相关文章

      网友评论

          本文标题:android kotlin 自定义随手动的小球

          本文链接:https://www.haomeiwen.com/subject/hlzrrftx.html