自定义view,跟随手指滑动的圆球
来源:互联网 发布:java面试一般会问什么 编辑:程序博客网 时间:2024/04/25 13:44
最近在学习自定义控件,菜鸟一枚,自己写的东西大神勿喷,仅作交流
废话不多说,直接上码
package com.jingcai.fu.planegame;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.View;/** * Created by Administrator on 2016/3/11. */public class DrawView extends View { public float currentX= 40; public float currentY= 50; //定义创建画笔 Paint paint =new Paint(); public DrawView(Context context) { super(context); } public DrawView(Context context,AttributeSet set) { super(context,set); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); //设置画笔的颜色 paint.setColor(Color.RED); canvas.drawCircle(currentX,currentY,15,paint); } @Override public boolean onTouchEvent(MotionEvent event) { //当前组件的currentX,currentY的两个属性 this.currentX = event.getX(); this.currentY = event.getY(); //通知该组件重绘 this.invalidate(); //返回true表明方法已经处理事件 return true; }}
还有xml布局
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.jingcai.fu.planegame.MainActivity"> <com.jingcai.fu.planegame.DrawView android:layout_width="wrap_content" android:layout_height="wrap_content"/></RelativeLayout>在代码中不需要做处理 一个跟着手指运动的view就出来了
0 0
- 自定义view,跟随手指滑动的圆球
- 自定义ViewGroup[跟随手指移动的view]
- 自定义View圆圈跟随手指的demo
- View滑动-跟随手指移动
- Android自定义View之跟随手指一起滑动的五色的小球
- 自定义跟随手指移动view
- Android 自定义 UI-----跟随手指滑动的小球
- 自定义的View,实现一个跟随手指的小球
- android从零开始-开发自定义View-跟随手指移动的小球
- 自定义圆形View:实现跟随手指移动的小球
- 手指在屏幕上滑动,红色的小球始终跟随手指移动(自定义控件)
- 一个跟随手指滑动的Button
- Android 跟随手指滑动的控件
- label跟随手指滑动
- android 跟随手指移动的 view
- Android之自定义View实现随手势滑动的小圆球
- 滑动跟随手指横向滑动
- 自定义组件-跟随手指的小球
- Flume日志收集
- 免费馅饼
- Chapter 11. Frame, MainWindow, and Toplevel Widgets 框架,主窗体,顶级部件
- Java的jdbc使用addBatch进行批处理操作的几种方式
- metrics和graphite监控
- 自定义view,跟随手指滑动的圆球
- Apach配置本地仿服务器连接
- 寻找空洞
- online_judge_1391
- 按两下退出APP代码
- Starting MySQL.Manager of pid-file quit without updating file.[FAILED]
- AsyncTask学习记录
- OnGlobalLayoutListener获得一个视图的高度
- nodejs 读取文件中的几行