- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Android轻松画出触摸轨迹由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例介绍了android如何画出触摸轨迹的方法,分享给大家供大家参考,具体内容如下 。
效果图:
实现代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
package
com.android.gameview5;
import
android.app.activity;
import
android.content.context;
import
android.graphics.canvas;
import
android.graphics.color;
import
android.graphics.paint;
import
android.graphics.path;
import
android.os.bundle;
import
android.view.motionevent;
import
android.view.surfaceholder;
import
android.view.surfaceholder.callback;
import
android.view.surfaceview;
import
android.view.window;
import
android.view.windowmanager;
public
class
surfaceviewactivity3
extends
activity {
public
void
oncreate(bundle s){
super
.oncreate(s);
//全屏显示
requestwindowfeature(window.feature_no_title);
getwindow().setflags(windowmanager.layoutparams.flag_fullscreen,
windowmanager.layoutparams.flag_fullscreen);
setcontentview(
new
myview(
this
));
}
public
class
myview
extends
surfaceview
implements
callback,runnable{
public
static
final
int
time_in_frame =
50
;
paint mpaint =
null
;
paint mtextpaint =
null
;
surfaceholder msurfaceholder =
null
;
boolean
mrunning =
false
;
canvas mcanvas =
null
;
private
path mpath;
private
float
mposx,mposy;
public
myview(context context){
super
(context);
this
.setfocusable(
true
);
this
.setfocusableintouchmode(
true
);
msurfaceholder =
this
.getholder();
msurfaceholder.addcallback(
this
);
mcanvas =
new
canvas();
mpaint =
new
paint();
mpaint.setcolor(color.black);
mpaint.setantialias(
true
);
mpaint.setstyle(paint.style.stroke);
mpaint.setstrokecap(paint.cap.round);
mpaint.setstrokewidth(
6
);
mpath =
new
path();
mtextpaint =
new
paint();
mtextpaint.setcolor(color.black);
mtextpaint.settextsize(
15
);
}
public
boolean
ontouchevent(motionevent event){
int
action = event.getaction();
float
x = event.getx();
float
y = event.gety();
switch
(action){
case
motionevent.action_down:
mpath.moveto(x, y);
break
;
case
motionevent.action_move:
mpath.quadto(mposx, mposy, x, y);
break
;
case
motionevent.action_up:
//mpath.reset();
break
;
}
//记录当前触摸点得当前得坐标
mposx = x;
mposy = y;
return
true
;
}
private
void
ondraw(){
mcanvas.drawcolor(color.white);
//绘制曲线
mcanvas.drawpath(mpath, mpaint);
mcanvas.drawtext(
"当前触笔x:"
+mposx,
0
,
20
,mtextpaint);
mcanvas.drawtext(
"当前触笔y:"
+mposy,
0
,
40
,mtextpaint);
}
public
void
run() {
// todo auto-generated method stub
while
(mrunning){
long
starttime = system.currenttimemillis();
synchronized
(msurfaceholder){
mcanvas = msurfaceholder.lockcanvas();
ondraw();
msurfaceholder.unlockcanvasandpost(mcanvas);
}
long
endtime = system.currenttimemillis();
int
difftime = (
int
) (endtime - starttime);
while
(difftime<=time_in_frame){
difftime =(
int
)(system.currenttimemillis()-starttime);
thread.yield();
}
}
}
@override
public
void
surfacechanged(surfaceholder holder,
int
format,
int
width,
int
height) {
// todo auto-generated method stub
}
@override
public
void
surfacecreated(surfaceholder holder) {
mrunning =
true
;
new
thread(
this
).start();
}
@override
public
void
surfacedestroyed(surfaceholder holder) {
// todo auto-generated method stub
mrunning =
false
;
}
}
}
|
以上就是android轻松画出触摸轨迹的具体方法,希望对大家的学习有所帮助.
最后此篇关于Android轻松画出触摸轨迹的文章就讲到这里了,如果你想了解更多关于Android轻松画出触摸轨迹的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我该怎么做 touch R 中的文件(即更新其修改时间而不更改其内容)?我正在寻找一个跨平台的内置(或打包)等效于: system2("touch", file_name) 最佳答案 我找到了 an
我想在 android 中实现 body 部位选择。我的要求是,当我点击特定部分时,图像应用程序应该能够识别 body 部位并且所选部分的颜色应该改变。附上示例图像以供引用。 如有任何想法或建议,我们
我需要将3D模型加载到我的应用程序中(不是游戏,它没有任何区别),并检测用户何时触摸此模型的特定部分以采取不同的操作。 我怎样才能做到这一点?可能吗? 最佳答案 我不熟悉Rajawali,但GitHu
似乎连续触摸总是被它起源的控件捕获。是否有标准方法将触摸/手势传递给当前触摸结束的控件? 最佳答案 控件显示在 UIView 对象内部的屏幕上。 iOS 使用第一响应者的概念来处理 UIView 对象
我有一个 UIScrollView 实例,允许用户放大/缩小。我已经根据文档实现了一个委托(delegate)来处理这个问题。但是,我想知道用户触摸 ScrollView 的位置(相对于 Scroll
我正在创建一款射击游戏,您可以触摸屏幕,玩家可以射击。我遇到的问题是,当你触摸屏幕并按住它并拖动它时,它会快速射击。处理这个问题的最佳方法是什么? 我希望玩家能够按住手指并以稳定的速度射击,而手指向上
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typ
这是我从触摸事件中获得的返回数据。明显缺少任何有用的触摸 X/Y 坐标 ( https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/ch
因此,我有一个屏幕,其中包含 0 到 6 个通过 XML 包含的相同用户界面组件。类似这样的东西: ...等等 每个包含的 UI 都是我重复使用的几个小部件和自定义组件的集
我希望能够更改文件的修改日期以便在 Web 应用程序中使用。目前我直接在命令行上测试这个。在我的 Mac 上工作正常,但是当我在 Linux 服务器上执行此操作时出现错误。 命令:/bin/touch
概念问题: 我在使用 touches 时遇到了一个非常简单的问题属性,自动更新依赖模型的时间戳;它正确地这样做了,但也应用了全局范围。 有什么办法可以关闭这个功能吗?或专门询问自动 touches忽略
我很难在一个简单的等距 Sprite Kit 游戏中实现点击处理。 我有一个包含多个 Tile 对象(SKSpriteNode)的 map (SKNode)的游戏场景(SKScene)。 这是 map
有没有办法在触摸事件后恢复 Flexslider 幻灯片的自动播放?现在看来,一旦我滑动导航,幻灯片就会停止...... 最佳答案 FLEXISLIDER 2 更新 resume()事件不再存在,正确
有些游戏有一些小图片作为 Sprite ,可以通过触摸来移动。如果 Sprite 是较大的图片,触摸是很正常的。我们可以使用函数CGRectContainsPoint检查 Sprite 。但是当 Sp
我有一个 View 覆盖到 iPhone 的相机 View 上。在此 View 中,我有一些 uibuttons,它们显示的位置取决于加速度计/指南针的值。当用户在 View 内触摸但没有在 uibu
我有一个 UIView 和一个 UIWebView。 UIWebView 是 UIView 的 subview 。 UIWebView 包含 YouTube 视频,并设置为让视频适合 UIWebVie
我是通过 XCode 使用 SDK 版本 5.0 进行 iOS 开发的新手。在我的应用程序中,我需要在按下按钮时更改按钮的标题。 假设在正常状态下它是“未推送”的。我所需要的是,当我按下按钮时,按钮标
我需要防止我的网络应用程序中的水平滚动。我尝试在 touchmove 事件上使用 PreventDefault(),但它也阻止垂直滚动。 有什么想法吗?^^ 我的尝试: $(document)
对于完全适合动画组方法的动画效果,如Brad Larson's answer here所示,我需要动画根据输入进行。特别是触摸和检测到的触摸的位置。处理 TouchMoved: 并为每次触摸设置元素的
我在屏幕上散布了一系列硬币。我想在触摸硬币时添加声音。 private Music coinSound; 在 show() 中: coinSound=assetManager.get(Assets.c
我是一名优秀的程序员,十分优秀!