如果你想要两个布局,一个活的和一个死一个,你应该添加自己View.OnTouchListener
他们每个人。
我做了一个例子,这里是活动:
public class MainActivity extends ActionBarActivity {
TextView text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout linearLayoutDead = (LinearLayout) findViewById(R.id.dead);
linearLayoutDead.setOnTouchListener(onTouchDeadListener);
LinearLayout linearLayoutLive = (LinearLayout) findViewById(R.id.live);
linearLayoutLive.setOnTouchListener(onTouchLiveListener);
text = (TextView) findViewById(R.id.textView);
}
private View.OnTouchListener onTouchDeadListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
text.setText(motionEvent.toString());
return false;
}
};
private View.OnTouchListener onTouchLiveListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
text.setText(motionEvent.toString());
return true;
}
};
}
而且布局:
<?xml version="1.0" encoding="utf-8"?>
我们覆盖OnTouch
方法,你会发现,当我们在“死区”单个或多个触摸,我们得到的初步反应,但没有进一步。 但是,当我们在“活区”中进行第一次触摸并且在死区中进行第二次触摸时,情况如何?
对于这种情况,你应该添加一个新的条件,您OnTouch
方法,像这样:
private View.OnTouchListener onTouchLiveListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getPointerCount()>1){
if(motionEvent.getY(1) > someNumber){
//Case when we touch the dead zone, TODO do some ...
}
}
text.setText(motionEvent.toString());
return true;
}
};
因此,在这种特殊情况下,我们可以检查当触摸“活区”下发生,根本不理会它或实现我们想要的任何行为。
希望这可能会有所帮助。 关注 何塞
对不起这是我早期的Android尝试。我不再与这个项目有关(实际上近两年)。我记得我实施了一种相同的解决方案。我的触摸屏处理过滤掉了区域内的水龙头,并移除了额外的坐标。在成功的过程中,我成功地过滤了他们想要的东西,但项目本身早已完成。 – OGP 2015-02-24 13:42:25