问题描述
您好我想创建aplication它加载大的图像和简单的手势,我可以通过它移动。我要像打印出来,但我无法实现onTouch因此它保持静止。任何帮助preseated。谢谢
我的code绘制出来的画面:
@覆盖保护无效的OnDraw(帆布油画){
super.onDraw(画布);
涂料粉刷=新的油漆();
paint.setStyle(Paint.Style.FILL);
//使整个画布白色
paint.setColor(Color.WHITE);
canvas.drawPaint(油漆);
paint.setStrokeWidth(1);
paint.setPathEffect(空);
paint.setColor(Color.GRAY);
paint.setAntiAlias(真正的);
的for(int i = 1; I< 100;我++){
canvas.drawLine(0,I * 1,600,I * 20,油漆);
canvas.drawLine(I * 1,0,I * 20,600,油漆);
}
}
在你看来,你需要创建OnTouchListener,这应该是这个样子:
myView.setOnTouchListener(新View.OnTouchListnener(){
@覆盖
公共布尔onTouch(视图V,MotionEvent E){
开关(e.getAction()){
案例MotionEvent.ACTION_DOWN:
//和code会在这里把手指在屏幕上
我会看看 MotionEvent 并寻找各种水平。你要注意它是如何打包的移动信息数位成一个 MotionEvent。
Hi I want to create aplication which loads large image, and simple gesture I can move across it. I have to image printed out but I can not implement onTouch so it remains stationary. Any help apreseated. Thanks
My code for drawing out the picture:
@Override protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
// make the entire canvas white
paint.setColor(Color.WHITE);
canvas.drawPaint(paint);
paint.setStrokeWidth(1);
paint.setPathEffect(null);
paint.setColor(Color.GRAY);
paint.setAntiAlias(true);
for (int i=1; i < 100; i++){
canvas.drawLine(0, i*1 , 600, i*20, paint);
canvas.drawLine(i*1 ,0, i*20, 600, paint);
}
}
Within your view, you need to create the "OnTouchListener" which should look something like this:
myView.setOnTouchListener(new View.OnTouchListnener(){
@Override
public boolean onTouch(View v, MotionEvent e){
switch(e.getAction()){
case MotionEvent.ACTION_DOWN:
//and code will go here for putting the finger on the screen
I would have a look at MotionEvent and looking at the various levels. You'll want to pay attention to how it can pack several bits of movement information into one MotionEvent.
这篇关于我怎样才能实现onTouch功能的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!