我得到一个滚动视图,里面有一些带有imageView的线性布局。
<ScrollView
android:layout_weight="41"
android:layout_width="0dip"
android:layout_height="match_parent"
android:background="@color/light_red_zone"
android:id="@+id/scrl_pass"
android:clickable="true"
android:layout_gravity="center">
<LinearLayout
android:id="@+id/lytPass"
android:background="@color/light_red_zone"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left" />
</ScrollView>
我在LinearLayout中动态添加imageView,它有一个监听器
img1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
savelog(new Dat_Log_DA(id_tile, Long.toString(System.currentTimeMillis()), id_configurazione));
if (semaphoreAudio.tryAcquire()) {
play(m1);
}
}
});
只需在触摸图像时启动媒体播放器。
然后,我需要在滚动视图上获取动作事件,所以我在滚动视图中添加了一个触摸侦听器
scrl_pass = (ScrollView) findViewById(R.id.scrl_pass);scrl_pass.setOnTouchListener(new View.OnTouchListener() {
private float mY = 0;
private static final String tag = "SCROLL VIEW";
@Override
public boolean onTouch(View v, MotionEvent motionEvent) {
Log.d(tag, "ACTION " + motionEvent.getActionMasked());
if ((motionEvent.getActionMasked() == MotionEvent.ACTION_DOWN) || (motionEvent.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN)) {
mY = motionEvent.getY();
Log.d(tag, "ACTION DOWN " + mY);
} else if ((motionEvent.getActionMasked() == MotionEvent.ACTION_UP) || (motionEvent.getActionMasked() == MotionEvent.ACTION_POINTER_UP)) {
Log.d(tag, "Action da " + mY + " a " + motionEvent.getY());
float currentPosition = scrl_pass.getScrollX();
}
return false;
}
});
问题是我得到ACTION_MOVE(id = 2)和ACTION_UP(id = 1),但如果在其中一个图像视图上执行了ACTION_DOWN,我就不会得到ACTION_DOWN