鼠标拖动圆运动
来源:互联网 发布:阿里云虚拟 编辑:程序博客网 时间:2024/06/05 19:39
//Mainty
package com.example.myapplication.view;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;import android.view.WindowManager;/** * Created by 123 on 2017/11/30. */public class BallViewDemo extends View{ private Paint paint; Context context; //圆的初始位置坐标 private float x=18; private float y=18; private int radius=100; /** * java代码创建时调用 * @param context */ public BallViewDemo(Context context) { super(context); this.context=context; } public BallViewDemo(Context context, @Nullable AttributeSet attrs) { super(context, attrs); this.context=context; } public BallViewDemo(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); this.context=context; } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.WHITE); paint=new Paint(); paint.setColor(Color.RED); paint.setAntiAlias(true); canvas.drawCircle(x,y,radius,paint); } @Override public boolean onTouchEvent(MotionEvent event) { this.x=(float)event.getX(); this.y=(float)event.getY(); invalidate(); return true; }}
//xml
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout 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:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.myapplication.app2"> <com.example.myapplication.view.BallViewDemo android:layout_width="wrap_content" android:layout_height="wrap_content" /></android.support.constraint.ConstraintLayout>
阅读全文
0 0
- 鼠标拖动圆运动
- MFC 鼠标拖动画圆
- MFC 鼠标拖动画圆
- 自定义View 鼠标拖动圆
- 鼠标运动
- 鼠标拖动
- 鼠标拖动
- 鼠标拖动
- unity 2d鼠标拖动卡牌运动,发现鼠标与物体的实际运行位置不一致
- 随机运动+可拖动效果
- 鼠标拖动JavaScript
- 鼠标拖动图片-javascript
- 鼠标拖动DIV
- C# 鼠标拖动图片
- 鼠标拖动Div
- 鼠标拖动控件
- 鼠标拖动控件
- 鼠标拖动层移动
- Djava.ext.dirs
- Eclipse一直building workspace: invoking maven project builder卡主
- Golang语法的踩坑总结(持续更新中)
- 通过uwsgi和nginx部署django项目
- I can 前端-06 静态网页到动态网页的过渡
- 鼠标拖动圆运动
- Java环境搭建
- python实现斐波拉契数列的看法
- CSS锚点
- Python 3.6 模块安装“error: Microsoft Visual C++ 14.0 is required...”问题解决
- tensorflow实践系列 -- 线性规划 (batch and stochastic)
- 解决Chrome表单文本框自动填充黄色背景色的黑科技
- 【异常】关于使用ES的RestHighLevel JavaAPI执行search操作时,参数的问题
- JVM必知必会(四)【收集器选择,G1】