Android 触摸一组或一排按钮
首先,英语不是我的第一语言,但我会尽我最大的努力。我不熟悉安卓系统。如图所示,如何用一个手指或一次触摸找到三个或四个触摸按钮 我创建了包含按钮的RelativeLayout,@Override onTouch Listener()。我读了安卓系统,但我不明白它是怎么做到的。我需要一个具体的例子来理解如何一次从一组按钮中获取触摸事件Android 触摸一组或一排按钮,android,android-imageview,android-button,android-event,android-touch-event,Android,Android Imageview,Android Button,Android Event,Android Touch Event,首先,英语不是我的第一语言,但我会尽我最大的努力。我不熟悉安卓系统。如图所示,如何用一个手指或一次触摸找到三个或四个触摸按钮 我创建了包含按钮的RelativeLayout,@Override onTouch Listener()。我读了安卓系统,但我不明白它是怎么做到的。我需要一个具体的例子来理解如何一次从一组按钮中获取触摸事件 public class MainActivity extends Activity implements OnTouchListener { Butto
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;
}
}
您希望用户执行连接按钮的滑动操作,还是希望用户同时触摸所有按钮?代码可能会有所不同,如果您包含这些信息,这将非常有用。我希望用户一次触摸所有按钮。事实上,消息toast不是应用程序的内容。我使用它作为应用程序的示例。是句子的安装,这样当用户每次触摸一排按钮时,触摸就是一个有效的句子。在触摸了一些正确的句子后移到第二阶段,但我现在需要的是如何触摸按钮在一起。非常感谢您在动作移动块中,您应该在相对布局上获得X和Y的触摸,然后计算X和Y下的按钮。差不多吧。从按钮可以得到左上角的宽度、高度和x、y坐标。我认为这是一个复杂的方法,但我尝试过。谢谢。您可能想看看多点触控事件教程-