我有以下布局:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedscrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/inner_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<NESTED VIEWS>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:id="@+id/outer_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<OUTER VIEWS>
</LinearLayout>
</LinearLayout>
</ScrollView>我的问题是,我希望ScrollView首先滚动,如果ScrollView移动了一点点,否则NestedScrollView就会消耗触摸。目前,NestedScrollView获取触摸事件,并且只在ScrollView接收触摸之后才使用滚动。我试过使用onInterceptTouchEvent并对其进行了实验,但没有结果。有什么指示吗?
这是正确的方法,还是使用其他视图组合?(可能是协调员的布局?)
发布于 2015-12-23 09:28:18
因此,我扩展了ScrollView并使其工作如下:
private static final int SCROLL_THRESHOLD = 10;
private boolean mScrolling;
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (getScrollY() > SCROLL_THRESHOLD) {
mScrolling = true;
onTouchEvent(ev);
return false;
} else if (mScrolling) {
mScrolling = false;
return false;
}
if (ev.getActionMasked() == MotionEvent.ACTION_UP) {
mScrolling = false;
}
return super.onInterceptTouchEvent(ev);
}为我工作。如果有人有更好的解决办法,请告诉我。
https://stackoverflow.com/questions/34430584
复制相似问题