我的android程序需要一些帮助。我需要在每次触摸时显示几个TextView。第一次触摸= TextView1,第二次触摸= TextView2等。我在ACTION_DOWN之后尝试使用ACTION_POINTER_DOWN创建它,但它只需一次触摸即可显示所有文本视图。
public boolean onTouch(View v, MotionEvent event) {
boolean inTouch = false;
int actionMask = event.getActionMasked();
tv = (TextView) findViewById(R.id.textView3);
tv1 = (TextView) findViewById(R.id.textView4);
tv2 = (TextView) findViewById(R.id.textView5);
tv3 = (TextView) findViewById(R.id.textView6);
int pointerCount = event.getPointerCount();
int downPI = 0;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: // 1st touch
inTouch = true;
case MotionEvent.ACTION_POINTER_DOWN: // next touches
downPI = pointerCount;
switch (downPI) {
case 0:
tv.setVisibility(View.VISIBLE);
break;
case 1:
tv1.setVisibility(View.VISIBLE);
break;
case 2:
tv2.setVisibility(View.VISIBLE);
break;
case 3:
tv3.setVisibility(View.VISIBLE);
break;
}
break;
}
return false;
答案 0 :(得分:0)
尝试以下解决方案: -
只需在onCreate()
上方添加以下行(定义变量): -
int downPI = 0;
并在onTouch
中对代码进行评论: -
// downPI = pointerCount;
和return false;
之前的增量一样: -
if(downPI < 3)
downPI++;
return false;