【发布时间】:2016-08-15 17:03:48
【问题描述】:
我有一个ScrollView 和一个嵌套的TextView。当我将setOnTouchListener 设置为它时,手势被识别但滚动不起作用。如果我将setOnTouchListener 设置为嵌套TextView,它工作正常。我已经尝试通过谷歌搜索但无法解决问题。
但我需要将setOnTouchListener 设置为ScrollView。
请帮忙。
layout.xml
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:id="@+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:background="#00FF00"
android:padding="15dp"
android:textSize="18sp" />
</LinearLayout>
</ScrollView>
MainActivity.java
mGestureDetector = new GestureDetectorCompat(this,this);
findViewById(R.id.scrollView).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, final MotionEvent event) {
Log.e("Stark", "setOnTouchListener");
mGestureDetector.onTouchEvent(event);
return true;
}
});
【问题讨论】:
-
不完全确定,但我相信您是说 onTouch 中的 return true 是它处理了 touchevent。这样 ScrollView 将不再处理触摸事件(滚动)
-
你震撼了。它通过将 return 设置为 false 来工作。谢谢:)
标签: android scrollview android-gesture