Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
440 views
in Technique[技术] by (71.8m points)

Android work multitouch button

Hi i want to create 2 Button and i want to multitouch ??

i tryed to do but no example in internet..

So if you got one can you share or can you give me opinion ?? my code is this but not support multitouch

 package multi.touch;

 import android.app.Activity;
 import android.os.Bundle;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.View.OnTouchListener;
 import android.widget.AbsoluteLayout.LayoutParams;
 import android.widget.Button;
 import android.widget.TextView;

 public class baslat extends Activity implements OnTouchListener  { 
 TextView yazi;
 TextView bir,iki;
 Button buton1,buton2;

 @Override public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

 yazi=(TextView)findViewById(R.id.textView1);
 bir=(TextView)findViewById(R.id.textView2);
 iki=(TextView)findViewById(R.id.textView3);
 buton1=(Button)findViewById(R.id.button1);
 buton2=(Button)findViewById(R.id.button2);

 buton2.setOnTouchListener(this);

 buton1.setOnTouchListener(this);

 }
 @Override
 public boolean onTouchEvent(MotionEvent event) {
    yazi.setText(String.valueOf(event.getPointerCount()+"

"));
            bir.setText(String.valueOf("Birinci "
 + (int)event.getX(0)+"

"+(int)event.getY(0)));
        iki.setText(String.valueOf("Ikinci"+
 (int)event.getX(1)+"

"+(int)event.getY(1)));
    //buton2.setLayoutParams(new
 LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,
 (int)event.getX(0),
 (int)event.getY(0)));      return
 super.onTouchEvent(event);
            } @Override public boolean onTouch(View v, MotionEvent event) {
    Button fds=(Button)v;


            return false; }


 }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Old question but I was running my head in the wall with this problem until I finally came across just setting

android:splitMotionEvents="true"

on the layout view that contains the button views, which allows for multiple buttons to be pressed, which I found digging in the ApiDemos that are available in the sdk demos download


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...