0

首先,英语不是我的第一语言,但我会尽力而为。我是安卓新手。如图所示,如何用一根手指或一键发现三个或四个触摸按钮?

在此处输入图像描述

我创建了包含按钮的RelativeLayout,@Override onTouch Listener()。我在 Android 上阅读,但我不明白它是如何完成的。我需要一个具体的例子来了解如何一次从一组按钮中获取触摸事件。

public class MainActivity extends Activity implements OnTouchListener    {
  Button button1,button2,button3,button4,
  button5,button6,button7,button8,button9;

  RelativeLayout relative;  

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    button1 =(Button)findViewById(R.id.b1);
    button2 =(Button)findViewById(R.id.b2); 
    button3 =(Button)findViewById(R.id.b3); 
    button4 =(Button)findViewById(R.id.b4); 
    button5 =(Button)findViewById(R.id.b5); 
    button6 =(Button)findViewById(R.id.b6); 
    button7 =(Button)findViewById(R.id.b7); 
    button8 =(Button)findViewById(R.id.b8); 
    button9 =(Button)findViewById(R.id.b9); 
    relative = (RelativeLayout)findViewById(R.id.re);

    button1.setOnTouchListener(this);
    button2.setOnTouchListener(this);
    button3.setOnTouchListener(this);
    button4.setOnTouchListener(this);
    button5.setOnTouchListener(this);
    button6.setOnTouchListener(this);
    button7.setOnTouchListener(this);
    button8.setOnTouchListener(this);
    button9.setOnTouchListener(this);
    relative.setOnTouchListener(this);
  }

  @Override
  public boolean onTouch(View v, MotionEvent event) {
    switch(event.getAction()){
      case MotionEvent.ACTION_DOWN:
      break;

      case MotionEvent.ACTION_MOVE:
      //How to find out that touch was done from button13 to button9            
      break;

      case MotionEvent.ACTION_UP:
      break;
    }   
    return true;
  }
}
4

0 回答 0