• android 开发 View _7_ 动态自定义View


    效果图:

    代码:

    package com.example.lenovo.mydemo.myViewDemo;
    
    import android.content.Context;
    import android.content.res.TypedArray;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.Typeface;
    import android.support.annotation.Nullable;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.View;
    
    import com.example.lenovo.mydemo.R;
    
    /**
     * Created by lenovo on 2018/7/2.
     */
    
    public class MyView_1 extends View {
        private final String TAG = "MyView_1";
        private Paint mPaint;
        private int i = 0;
    
        public MyView_1(Context context) {
            super(context);
        }
    
        public MyView_1(Context context, @Nullable AttributeSet attrs) {
            super(context, attrs);
        }
    
        public MyView_1(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
    
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    
    
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            mPaint = new Paint();
            mPaint .setStrokeWidth(20);
            mPaint.setColor(Color.RED);
            canvas.drawLine(0,100,i,100,mPaint);
            if (i==500){
                i=0;
            }else {
                i=i+10;
            }
            postInvalidateDelayed(100);//延时100毫秒刷新
    
        }
    }
  • 相关阅读:
    yii2.0 干货
    VLD opcodes 在线查看
    定长顺序串的实现
    循环队列
    oracle--DG初始化参数
    oracle --工具 ODU
    Oracle RAC 修改SPFILE路径 文件查看
    oracle 错误 ORA-00020问题解析
    oracle 错误 TNS-01190与oracle 登入没反应操作
    Oracle--RMAN Recover 缺失的归档操作
  • 原文地址:https://www.cnblogs.com/guanxinjing/p/9708599.html
Copyright © 2020-2023  润新知