单点触控
来源:互联网 发布:芜湖一中王海飞 知乎 编辑:程序博客网 时间:2024/05/24 03:12
//**********************************************************DrawView类
/
package com.example.diandianchukong;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.support.annotation.Nullable;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.View;/** * Created by dell on 2017/9/1. */public class DrawView extends View { public float currentX = 40; public float currentY = 50; Paint p = new Paint(); public DrawView(Context context) { super(context); } public DrawView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); p.setColor(Color.BLUE); canvas.drawCircle(currentX, currentY, 15, p); } @Override public boolean onTouchEvent(MotionEvent event) { currentY = event.getY(); currentX = event.getX(); invalidate(); return true; }}
/****************************************************************/MainActivity 类package com.example.diandianchukong;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.widget.LinearLayout;public class MainActivity extends AppCompatActivity { private DrawView drawView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);// drawView = (DrawView) findViewById(R.id.drawview); LinearLayout root = (LinearLayout) findViewById(R.id.root); final DrawView drawView = new DrawView(this); drawView.setMinimumWidth(300); drawView.setMinimumHeight(500); root.addView(drawView); }}
/***********************************************************************layout类/<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/root" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.diandianchukong.MainActivity"></LinearLayout>
阅读全文
0 0
- 单点触控事件、
- 单点触控
- 单点触控
- 单点触控
- cocos2dx单点触控
- 单点触控
- 自定义View(单点触控)
- bVNC单点触控分析
- 多点触控与单点触控
- cocos2d-x3.2 单点触控
- 【unity3D】单点和多点触控
- COCOS学习笔记--单点触控
- 自定义圆加载进度单点触控
- 注册单点触屏
- HTML5触屏设备单点触控事件
- cocos2d-x学习笔记—单点触控
- Android 单点&多点触控实现-----USB接口
- HTML5触摸事件(多点、单点触控)
- BZOJ 3629: [JLOI2014]聪明的燕姿
- java 位运算符详解 及 实例 ---与(&),或(|),非(~),异或(^)
- 树莓派opencv的安装
- ArrayList和LinkedList的底层源码之我见
- 进制转换(char和string转换int)
- 单点触控
- C++ 【对若干个区间进行合并】
- tomcat+nginx+redis实现均衡负载、session共享(一)
- LEETCODE 48 672. Bulb Switcher II
- Javaweb之EL表达式
- Windows程序设计-窗口和消息
- Android的Cursor的close方法不调用会不会造成内存泄露
- 超简单!Linux下FTP服务器的安装和配置(基于Ubuntu)
- HDU 5877 Weak Pair (dfs 树状数组 || dfs序 主席树)