其他分享
首页 > 其他分享> > Android工作多点触控按钮

Android工作多点触控按钮

作者:互联网

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

我试着做但在互联网上没有例子..

所以如果你有一个可以分享或者你能给我意见吗?
我的代码是这个但不支持多点触控

 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; }


 }

解决方法:

老问题,但是我一直在墙上遇到这个问题,直到我终于遇到了设置

android:splitMotionEvents="true"

在包含按钮视图的布局视图上,允许按下多个按钮,我发现在sdk演示下载中可用的ApiDemos中挖掘

标签:sample,multi-touch,android,button
来源: https://codeday.me/bug/20190925/1816187.html