zoukankan      html  css  js  c++  java
  • Android代码写View

    1、Java Code

    package com.fish.helloworld;
    
    import android.app.Activity;
    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.KeyEvent;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(new TestMotionView(this));
        }
        
        public class TestMotionView extends View{
            private Paint mPaint = new Paint();
            private int mAction;
            private float mX;
            private float mY;
            
            public TestMotionView(Context c){
                super(c);
                mAction = MotionEvent.ACTION_POINTER_UP;
                mX = 0;
                mY = 0;
            }
            
            @Override
            protected void onDraw(Canvas canvas){
                Paint paint = mPaint;
                canvas.drawColor(Color.WHITE);
                if(MotionEvent.ACTION_MOVE == mAction){
                    paint.setColor(Color.RED);
                }else if(MotionEvent.ACTION_UP == mAction){
                    paint.setColor(Color.GREEN);
                }else if(MotionEvent.ACTION_DOWN == mAction){
                    paint.setColor(Color.BLUE);
                }
                canvas.drawCircle(mX, mY, 10, paint);
                setTitle("A = " + mAction + " [" + mX + "," +mY +"]");
            }
            @Override
            public boolean onTouchEvent(MotionEvent event){
                mAction = event.getAction();
                mX = event.getX();
                mY = event.getY();
                invalidate();
                return true;
            }
            
        }
        
    }
  • 相关阅读:
    springboot:集成fastjson(教训)
    记一次 SpringBoot2.x 配置 Fastjson 的坑--修正版
    国密开源代码
    国产加密SM3算法java实现
    国密算法Java代码的标准实现
    sm2,sm3,sm4国密算法的纯c语言版本,使用于任何嵌入式平台
    samtools pileup mpileup Format
    mormot multipart上传文件
    浅谈软件项目实施
    Linux CPU占用率监控工具小结
  • 原文地址:https://www.cnblogs.com/sshoub/p/3879403.html
Copyright © 2011-2022 走看看