由于滑动刷新布局,我无法向上滚动

时间:2019-04-10 15:40:46

标签: android swiperefreshlayout android-nestedscrollview

这么多类似的问题,但我的却有些不同。向下滚动时,活动将完美进行。但是,当我向上滚动而不是滚动时,它会刷新。我真正想要的是,只有当我位于嵌套滚动视图的顶部时,它才会刷新。我必须快速双击,才能向上滚动,这有点困难。

屏幕截图:

enter image description here

  

Details.xml

     <?xml version="1.0" encoding="utf-8"?>
  <android.support.v4.widget.SwipeRefreshLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipe_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".details">
 <android.support.design.circularreveal.
 coordinatorlayout.CircularRevealCoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true"
    >

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing"
        android:layout_width="match_parent"
        android:layout_height="350dp"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:contentScrim="#0e0d0e"
        app:expandedTitleTextAppearance="@android:color/transparent"
        >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/img_beach"
            android:contentDescription="@null"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"
            />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:title="Beach Name"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="parallax"
            />
    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>


<android.support.design.widget.FloatingActionButton
    android:id="@+id/btnSubmit"
    android:src="@drawable/send"
    android:backgroundTint="@android:color/white"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:elevation="6dp"
    app:layout_anchor="@id/app_bar_layout"
    app:layout_anchorGravity="bottom|right|end"
    app:pressedTranslationZ="12dp"
    app:useCompatPadding="true"
    />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/btn_rating"
    android:src="@drawable/ic_add_black_24dp"
    android:backgroundTint="@android:color/white"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:elevation="6dp"
    app:layout_anchor="@id/app_bar_layout"
    app:layout_anchorGravity="bottom|right|start"
    app:pressedTranslationZ="12dp"
    app:useCompatPadding="true"
    />

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardElevation="5dp"
            app:cardUseCompatPadding="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/beach_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:padding="12dp"
                    android:text="Food Name"
                    android:textColor="@color/colorPrimary"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <LinearLayout
                    android:id="@+id/layout_price"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:src="@drawable/money" />

                    <TextView
                        android:id="@+id/beach_price"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="9"
                        android:text="1,000"
                        android:textColor="@color/colorPrimary"
                        android:textSize="18sp"
                        android:textStyle="bold" />


                </LinearLayout>

                <com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
                    android:id="@+id/number_button"
                    android:layout_width="100dp"
                    android:layout_height="30dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginBottom="10dp"
                    app:backGroundColor="@color/number_button"
                    app:finalNumber="20"
                    app:initialNumber="1"
                    app:textSize="8sp" />

                <LinearLayout
                    android:id="@+id/layout_checkDate"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:orientation="horizontal">

                    <Button
                        android:id="@+id/checkInBTN"
                        android:layout_width="90dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:text="CHECK IN"
                        android:textSize="12sp" />

                    <TextView
                        android:id="@+id/checkInTV"
                        android:layout_width="90dp"
                        android:layout_height="match_parent"
                        android:layout_marginLeft="8dp"
                        android:layout_marginTop="6dp"
                        android:layout_marginBottom="10dp"
                        android:gravity="center_vertical"
                        android:text="CHECK IN DATE"
                        android:textAlignment="center" />

                    <Button
                        android:id="@+id/checkOutBTN"
                        android:layout_width="90dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:text="CHECK OUT"
                        android:textSize="12sp" />

                    <TextView
                        android:id="@+id/checkOutTV"
                        android:layout_width="90dp"
                        android:layout_height="match_parent"
                        android:layout_marginLeft="8dp"
                        android:layout_marginTop="6dp"
                        android:layout_marginBottom="10dp"
                        android:gravity="center_vertical"
                        android:text="CHECK OUT DATE"
                        android:textAlignment="center" />


                </LinearLayout>

                <LinearLayout
                    android:id="@+id/layout_checkAvailability"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:orientation="horizontal">

                    <Button
                        android:id="@+id/checkAvailabilityBTN"
                        android:layout_width="160dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:gravity="center|center_horizontal"
                        android:text="CHECK AVAILABILITY"
                        android:textSize="12sp" />

                </LinearLayout>


            </LinearLayout>


        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardElevation="5dp"
            app:cardUseCompatPadding="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <RatingBar
                    android:id="@+id/rating_bar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:isIndicator="true"
                    android:max="5"
                    android:rating="0" />

                <TextView
                    android:id="@+id/beach_description"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:lineSpacingMultiplier="1.5"
                    android:padding="12dp"
                    android:text="Description"
                    android:textColor="@android:color/black"
                    android:textSize="14sp" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardElevation="5dp"
            app:cardUseCompatPadding="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/beach_review"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="18dp"
                    android:lineSpacingMultiplier="1.5"
                    android:padding="12dp"
                    android:text="REVIEWS"
                    android:textColor="@android:color/black"
                    android:textSize="24sp"
                    android:textStyle="bold|italic" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recyclerComment"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />


            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardCornerRadius="12dp"
            app:cardUseCompatPadding="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/beach_gallery"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="18dp"
                    android:lineSpacingMultiplier="1.5"
                    android:padding="12dp"
                    android:text="GALLERY"
                    android:textColor="@android:color/black"
                    android:textSize="24sp"
                    android:textStyle="bold|italic" />

                <ImageView
                    android:id="@+id/img_beach2"
                    android:layout_width="match_parent"
                    android:layout_height="250dp"
                    android:scaleType="centerCrop"
                    android:src="@drawable/background" />

                <ImageView
                    android:id="@+id/img_beach3"
                    android:layout_width="match_parent"
                    android:layout_height="250dp"
                    android:layout_marginTop="20dp"
                    android:scaleType="centerCrop"
                    android:src="@drawable/background" />


                <ImageView
                    android:id="@+id/img_beach4"
                    android:layout_width="match_parent"
                    android:layout_height="250dp"
                    android:layout_marginTop="20dp"
                    android:scaleType="centerCrop"
                    android:src="@drawable/background" />

            </LinearLayout>

        </android.support.v7.widget.CardView>


    </LinearLayout>


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


 </android.support.design.circularreveal.
 coordinatorlayout.CircularRevealCoordinatorLayout>
 </android.support.v4.widget.SwipeRefreshLayout>
  

Details.java

        mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
            if(!menuID.isEmpty() && menuID != null){

                Query query = ratingTbl.orderByChild("menuID").equalTo(menuID);


                FirebaseRecyclerOptions<Rating> options = new FirebaseRecyclerOptions.Builder<Rating>()
                        .setQuery(query, Rating.class)
                        .build();

                adapter = new FirebaseRecyclerAdapter<Rating, ShowCommentViewHolder>(options) {
                    @Override
                    protected void onBindViewHolder(@NonNull ShowCommentViewHolder holder, int position, @NonNull Rating model) {

                        holder.ratingBar.setRating(Float.parseFloat(model.getRateValue()));
                        holder.txtComment.setText(model.getComment());
                        holder.txtUserEmail.setText(model.getUserEmail());

                    }

                    @NonNull
                    @Override
                    public ShowCommentViewHolder onCreateViewHolder(ViewGroup parent, int i) {
                        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.show_comment_layout, parent, false);
                        return new ShowCommentViewHolder(view);
                    }
                };

                loadComment(menuID);

            }
        }
    });
    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);

            if(!menuID.isEmpty() && menuID != null){

                Query query = ratingTbl.orderByChild("menuID").equalTo(menuID);


                FirebaseRecyclerOptions<Rating> options = new FirebaseRecyclerOptions.Builder<Rating>()
                        .setQuery(query, Rating.class)
                        .build();

                adapter = new FirebaseRecyclerAdapter<Rating, ShowCommentViewHolder>(options) {
                    @Override
                    protected void onBindViewHolder(@NonNull ShowCommentViewHolder holder, int position, @NonNull Rating model) {

                        holder.ratingBar.setRating(Float.parseFloat(model.getRateValue()));
                        holder.txtComment.setText(model.getComment());
                        holder.txtUserEmail.setText(model.getUserEmail());

                    }

                    @NonNull
                    @Override
                    public ShowCommentViewHolder onCreateViewHolder(ViewGroup parent, int i) {
                        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.show_comment_layout, parent, false);
                        return new ShowCommentViewHolder(view);
                    }
                };

                loadComment(menuID);
            }


        }
    });

4 个答案:

答案 0 :(得分:0)

我已经通过将“滑动刷新”布局放入“协调器”布局中来解决了该问题。非常感谢所有观众:)

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.circularreveal.coordinatorlayout.
CircularRevealCoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
tools:context=".details"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true"
    >

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing"
        android:layout_width="match_parent"
        android:layout_height="350dp"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:contentScrim="#0e0d0e"
        app:expandedTitleTextAppearance="@android:color/transparent"
        >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/img_beach"
            android:contentDescription="@null"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"
            />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:title="Beach Name"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="parallax"
            />
    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>


<android.support.design.widget.FloatingActionButton
    android:id="@+id/btnSubmit"
    android:src="@drawable/send"
    android:backgroundTint="@android:color/white"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:elevation="6dp"
    app:layout_anchor="@id/app_bar_layout"
    app:layout_anchorGravity="bottom|right|end"
    app:pressedTranslationZ="12dp"
    app:useCompatPadding="true"
    />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/btn_rating"
    android:src="@drawable/ic_add_black_24dp"
    android:backgroundTint="@android:color/white"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:elevation="6dp"
    app:layout_anchor="@id/app_bar_layout"
    app:layout_anchorGravity="bottom|right|start"
    app:pressedTranslationZ="12dp"
    app:useCompatPadding="true"
    />

<android.support.v4.widget.SwipeRefreshLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/swipe_layout"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardElevation="5dp"
            app:cardUseCompatPadding="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/beach_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:padding="12dp"
                    android:text="Food Name"
                    android:textColor="@color/colorPrimary"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <LinearLayout
                    android:id="@+id/layout_price"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:src="@drawable/money" />

                    <TextView
                        android:id="@+id/beach_price"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="9"
                        android:text="1,000"
                        android:textColor="@color/colorPrimary"
                        android:textSize="18sp"
                        android:textStyle="bold" />


                </LinearLayout>

                <com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
                    android:id="@+id/number_button"
                    android:layout_width="100dp"
                    android:layout_height="30dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginBottom="10dp"
                    app:backGroundColor="@color/number_button"
                    app:finalNumber="20"
                    app:initialNumber="1"
                    app:textSize="8sp" />

                <LinearLayout
                    android:id="@+id/layout_checkDate"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:orientation="horizontal">

                    <Button
                        android:id="@+id/checkInBTN"
                        android:layout_width="90dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:text="CHECK IN"
                        android:textSize="12sp" />

                    <TextView
                        android:id="@+id/checkInTV"
                        android:layout_width="90dp"
                        android:layout_height="match_parent"
                        android:layout_marginLeft="8dp"
                        android:layout_marginTop="6dp"
                        android:layout_marginBottom="10dp"
                        android:gravity="center_vertical"
                        android:text="CHECK IN DATE"
                        android:textAlignment="center" />

                    <Button
                        android:id="@+id/checkOutBTN"
                        android:layout_width="90dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:text="CHECK OUT"
                        android:textSize="12sp" />

                    <TextView
                        android:id="@+id/checkOutTV"
                        android:layout_width="90dp"
                        android:layout_height="match_parent"
                        android:layout_marginLeft="8dp"
                        android:layout_marginTop="6dp"
                        android:layout_marginBottom="10dp"
                        android:gravity="center_vertical"
                        android:text="CHECK OUT DATE"
                        android:textAlignment="center" />


                </LinearLayout>

                <LinearLayout
                    android:id="@+id/layout_checkAvailability"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:orientation="horizontal">

                    <Button
                        android:id="@+id/checkAvailabilityBTN"
                        android:layout_width="160dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:gravity="center|center_horizontal"
                        android:text="CHECK AVAILABILITY"
                        android:textSize="12sp" />

                </LinearLayout>


            </LinearLayout>


        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardElevation="5dp"
            app:cardUseCompatPadding="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <RatingBar
                    android:id="@+id/rating_bar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:isIndicator="true"
                    android:max="5"
                    android:rating="0" />

                <TextView
                    android:id="@+id/beach_description"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:lineSpacingMultiplier="1.5"
                    android:padding="12dp"
                    android:text="Description"
                    android:textColor="@android:color/black"
                    android:textSize="14sp" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardElevation="5dp"
            app:cardUseCompatPadding="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/beach_review"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="18dp"
                    android:lineSpacingMultiplier="1.5"
                    android:padding="12dp"
                    android:text="REVIEWS"
                    android:textColor="@android:color/black"
                    android:textSize="24sp"
                    android:textStyle="bold|italic" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recyclerComment"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />


            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardCornerRadius="12dp"
            app:cardUseCompatPadding="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/beach_gallery"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="18dp"
                    android:lineSpacingMultiplier="1.5"
                    android:padding="12dp"
                    android:text="GALLERY"
                    android:textColor="@android:color/black"
                    android:textSize="24sp"
                    android:textStyle="bold|italic" />

                <ImageView
                    android:id="@+id/img_beach2"
                    android:layout_width="match_parent"
                    android:layout_height="250dp"
                    android:scaleType="centerCrop"
                    android:src="@drawable/background" />

                <ImageView
                    android:id="@+id/img_beach3"
                    android:layout_width="match_parent"
                    android:layout_height="250dp"
                    android:layout_marginTop="20dp"
                    android:scaleType="centerCrop"
                    android:src="@drawable/background" />


                <ImageView
                    android:id="@+id/img_beach4"
                    android:layout_width="match_parent"
                    android:layout_height="250dp"
                    android:layout_marginTop="20dp"
                    android:scaleType="centerCrop"
                    android:src="@drawable/background" />

            </LinearLayout>

        </android.support.v7.widget.CardView>


    </LinearLayout>


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

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

答案 1 :(得分:0)

我在 OnScrollChangeListener 上添加了 ScrollView 以根据滚动的位置启用/禁用 SwipeRefreshLayout。仅当 scrollY 位于顶部并且它不会妨碍我的 scrollView 时,我才启用滑动刷新。

Kotlin 中的代码如下所示:

scrollView.setOnScrollChangeListener { v: View, scrollX: Int, scrollY: Int, _: Int, _: Int ->
        swipeRefreshLayout.isEnabled = scrollY == 0
}

答案 2 :(得分:0)

下面是这样解决的

 scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
        @Override
        public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
           if(scrollY > 5){
               mSwipeRefreshLayout.setEnabled(false);
           }else{
               mSwipeRefreshLayout.setEnabled(true);
           }

        }
    });

答案 3 :(得分:0)

如果 RecyclerViewListView 不是 SwipeRefreshLayout 的直接子代,则会出现此问题。

最简单的解决方案是提供 OnChildScrollUpCallback 实现并适当地返回结果。在下面的 Kotlin 代码中,refreshLayoutSwipeRefreshLayoutrecyclerViewRecyclerView,这也可以在 xml 布局代码中看到。

refreshLayout.setOnChildScrollUpCallback(object : SwipeRefreshLayout.OnChildScrollUpCallback {
  override fun canChildScrollUp(parent: SwipeRefreshLayout, child: View?): Boolean {
    if (recyclerView != null) {
      return recyclerView.canScrollVertically(-1)
    }
    return false
  }
})

虽然 xml 布局是这样的,

 <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/refreshLayout"
    ...
    lots of other views i.e TextView, ImageView, MotionLayout
    ...
    ...
    ...
    <androidx.recyclerview.widget.RecyclerView
       android:id="@+id/recyclerView".../>
       
    ...
    ...
    ...
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>