2

私は次のレイアウトを持っています:

<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 を使用して実験しましたが、役に立ちませんでした。ポインタはありますか?

これは正しいアプローチですか、それとも他のビューの組み合わせを使用しますか? (コーディネーター配置かな?)

4

1 に答える 1

1

だから私は 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);
}

私のために働きます。誰かがより良い解決策を持っているかどうか教えてください。

于 2015-12-23T09:28:18.757 に答える