RTF*_*RTF 5 android android-xml android-scrollview
我知道这样的问题已经有答案了,但我没有任何运气,所以这是最后的手段。
我有一个包含 ScrollView 的 LinearLayout。我希望 LinearLayout 响应单击、点击、触摸您想要调用的任何内容,但 ScrollView 会产生干扰,因此永远不会调用 LinearLayout 的单击处理程序。我不介意子类 ScrollView 和覆盖 onTouchEvent (但我不明白要放入什么),但替代解决方案也很好。我已经尝试在 LinearLayout、ScrollView 和 ScrollView 的第一个子项上使用requestDisallowInterceptTouch(true),但它不起作用(TBH,该方法的 javadoc 使我感到困惑)。
如果我在自定义滚动视图中使用此覆盖:
@Override
public boolean onTouchEvent(MotionEvent event) {
return false;
}
Run Code Online (Sandbox Code Playgroud)
... LinearLayout 确实响应点击,但完全禁用滚动,并且每种类型的触摸手势都会导致调用 LinearLayout 单击处理程序。那么,我需要做什么才能像往常一样处理滚动移动,并使 ScrollView 忽略点击/点击?
对于它的价值,XML 看起来像这样:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
.../>
<com.package.MyScrollView
android:id="@+id/my_scroller"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="vertical">
...
...
Run Code Online (Sandbox Code Playgroud)
一般情况下TextView区域会检测到LinearLayout注册的点击,而ScrollView不会。
尝试将 ScrollView 的 focusable 属性设置为 false。
<ScrollView
android:focusable="false"
>
<!-- other stuff-->
</ScrollView>
Run Code Online (Sandbox Code Playgroud)