35

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

<android.support.v4.widget.SwipeRefreshLayout
    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" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
            //some views here
        </LinearLayout>

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="*" >
        </TableLayout>

    </LinearLayout>

</android.support.v4.widget.SwipeRefreshLayout>

問題は、テーブルをスクロールダウンすると、swipelayout がトリガーされているため、再度 scrollUp できないことです。テーブルの最初のビューが表示されている場合にのみ、swiperrefresh をトリガーするにはどうすればよいですか?

4

4 に答える 4

104

ScrollViewを a に置き換えるとandroid.support.v4.widget.NestedScrollView、スクロール動作が期待どおりに機能することがわかりました。

于 2016-12-12T15:30:03.193 に答える
10

SwipeRefreshLayout の独自の実装を作成し、次の方法で canChildScrollUp をオーバーライドします。

    @Override
public boolean canChildScrollUp() {
    if (scrollView != null)
        return scrollView.canScrollVertically(-1);

    return false;
}

ScrollView の任意のサブクラスに置き換えるだけです。

于 2014-09-29T12:26:41.023 に答える
-3

NestedScrollView を次のように使用します。

     app:layout_behavior="@string/appbar_scrolling_view_behavior"
于 2018-02-26T22:21:50.883 に答える