Android的工作多点触控按钮多点、按钮、触控、工作

2023-09-12 10:14:25 作者:灵魂已死去

我想创建2个按钮,我想多点触控??

我trye​​d做,但在网上没有例子。

所以,如果你得到了一个可以大家分享,或者你可以给我的意见? 我的code是这样,但不支持多点触控。

 包multi.touch;

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

 baslat扩展活动的公共类实现OnTouchListener {
 TextView的伢子;
 TextView的井,壹岐;
 按钮buton1,buton2;

 @覆盖公共无效的onCreate(包savedInstanceState){
 super.onCreate(savedInstanceState);
 的setContentView(R.layout.main);

 丫子=(TextView中)findViewById(R.id.textView1);
 BIR =(TextView中)findViewById(R.id.textView2);
 壹岐=(TextView中)findViewById(R.id.textView3);
 buton1 =(按钮)findViewById(R.id.button1);
 buton2 =(按钮)findViewById(R.id.button2);

 buton2.setOnTouchListener(本);

 buton1.setOnTouchListener(本);

 }
 @覆盖
 公共布尔的onTouchEvent(MotionEvent事件){
    yazi.setText(将String.valueOf(event.getPointerCount()+\ñ\ N));
            bir.setText(将String.valueOf(Birinci
 +(INT)event.getX(0)+\ñ\ N+(INT)event.getY(0)));
        iki.setText(将String.valueOf(Ikinci+
 (INT)event.getX(1)+\ñ\ N+(INT)event.getY(1)));
    //buton2.setLayoutParams(new
 的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,
 (int)的event.getX(0),
 (int)的event.getY(0)));返回
 super.onTouchEvent(事件);
            } @覆盖公共布尔onTouch(视图V,MotionEvent事件){
    按钮FDS =(按钮)V;


            返回false; }


 }
 

解决方案

老问题,但我跑我的头在墙上的这个问题,直到我碰到只设置终于来了

 安卓splitMotionEvents =真
 

在包含该按钮的看法布局来看,它允许多个按钮是pressed,我发现挖掘可用在SDK中演示的ApiDemos下载

触碰 新视界 Windows7引领液晶格局

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()+"\n\n"));
            bir.setText(String.valueOf("Birinci "
 + (int)event.getX(0)+"\n\n"+(int)event.getY(0)));
        iki.setText(String.valueOf("Ikinci"+
 (int)event.getX(1)+"\n\n"+(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; }


 }

解决方案

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