NestedScrollView、ScrollView嵌套Recyclerview的冲突、显示不完整及焦点问题解决方案

ScrollView 嵌套 RecyclerView 滑动处理方案 你可以通过自定义来禁用其滚动功能。创建一个自定义的类,并重写和方法,使其不处理触摸事件。java@Override// 不处理触摸事件@Override// 不拦截触摸事件然后在你的布局文件中使用这个自定义的xml根据你的具体需求,可以选择以下方法之一来解决在中嵌套时,常见的问题包括滚动冲突和布局问题。通过禁用的嵌套滚动、设置固定高度、检查报错信息、动态设置高度等方法,可以有效解决这些问题。如果仍然遇到问题,建议详细检查报错信息,逐步排查问题所在。建议使用中嵌套这种方式去修改。 阅读详情

最近项目中嵌套的控件比较多,遇到了不少问题,昨天解决了,赶紧记录下

场景是ViewPager2嵌套NestedScrollView嵌套RecyclerView瀑布流

效果图:
没办法,压缩太严重,凑合看
在这里插入图片描述

主要问题如下:

  1. NestedScrollView / ScrollView嵌套RecyclerView冲突,不滚动、显示不完整、或者不显示问题
  2. NestedScrollView / ScrollView嵌套RecyclerView瀑布流双重滑动问题
  3. 打开页面后定位到RecyclerView问题

主要就这三个问题,下面按照顺序分别解决,NestedScrollView和ScrollView我试过了,效果没区别

问题一:NestedScrollView / ScrollView嵌套RecyclerView冲突,不滚动、显示不完整、或者不显示问题

关于该问题,是最主要的问题,优快云上说了很多都是要修改layout_height match_parent为wrap_content,其实这个没什么影响,因为问题本质是我们需要给RecyclerView一个固定的高度来解决的。

如果你设置为match_parent,就会出现不显示的效果,我们只要给RecyclerView设置一个固定的高度。或者动态计算控件高度,然后设置上,就可以解决该问题了。

我们可以在XML中给RecyclerView的layout_height设置一个固定高度,1000dp之类的,这样可以解决。但是我们没办法控制瀑布流的高度。但是实际开发中我们不能确定数据需要加载多高,所以写死高度可能不太好。所以布局代码就不贴了

换种思路就是动态计算出所需的高度,然后设置给他就可以了。

我这里是根据瀑布流数据的长度来处理的。可以根据具体的业务计算高度。

		// 计算需要高度
        ViewGroup.LayoutParams layoutParams = menuHomeBinding.rvWaterFallsFlow.getLayoutParams();
        int height = 0;
        for (int i = 0; i < waterFallsFlowBeanArrayList.size(); i++) {
            if (i % 2 == 0) {
                height += 400;
            } else if (i % 3 == 0) {
                height += 360;
            } else {
                height += 440;
            }
        }
        // 只要把业务处理后的高度赋值给layoutParams.height就可以了
        layoutParams.height = height - waterFallsFlowBeanArrayList.size() * 100;
        menuHomeBinding.rvWaterFallsFlow.setLayoutParams(layoutParams);

这样就可以了
我也有想过在Adapter中计算高度,然后得到后处理,但是试了下,获取的一直是0,如果有思路的可以告知下。

问题二:NestedScrollView / ScrollView嵌套RecyclerView瀑布流双重滑动问题

在正常显示后,会出现NestedScrollView / ScrollView滑动,里面的RecyclerView也可以滑动的效果。

这里我们需要处理一下,不让里面的RecyclerView滑动,而是随着NestedScrollView / ScrollView一起滑动。
这里呢,官方API中有一个属性,可以帮助我们解决这个问题。就是这个setNestedScrollingEnabled,这是启动嵌套滚动的开关。默认是true。

当然也可以在布局文件中设置,如果是在布局文件中设置,是要在RecyclerView上设置的。我这里是在代码中设置的。

		menuHomeBinding.rvWaterFallsFlow.setNestedScrollingEnabled(false);
问题三:打开页面后定位到RecyclerView问题

在上面的基础上,效果已经可以正常显示,但是打开App后就自动定位到RecyclerView的位置 了。

这是因为RecyclerView是默认自动获取焦点的,所以我们需要处理一下。有两种方式

XML方式和代码中设置的方式,先说一下区别:
在XML中设置,切换其他页面后回来,焦点总是在顶部(设置焦点的位置);
如果在代码中设置,切换页面后回来,位置会停留在之前浏览的位置。

下面是具体的解决方案。

  1. XML方式

    在NestedScrollView / ScrollView的第一个子控件上添加获取焦点的属性

                android:focusable="true"
                android:focusableInTouchMode="true"
这里需要说明一下,NestedScrollView和ScrollView都是只允许有一个子控件,这里说的第一个子控件是唯一子控件里面的第一个子控件。
<androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <!-- 第一个子控件-->
            <androidx.viewpager.widget.ViewPager
                android:id="@+id/vp_home_menu_banner"
                android:layout_width="match_parent"
                android:layout_height="160dp"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:layout_marginStart="10dp"/>
  1. 代码中处理

    第二中是在代码中处理。我采用的这种方式,也很简单。

    既然是RecyclerView默认自动获取焦点,那么我们只要在代码中设置不让他默认获取焦点就可以解决了。

		menuHomeBinding.rvWaterFallsFlow.setFocusable(false);
总结

基本上用到的属性就

		menuHomeBinding.rvWaterFallsFlow.setHasFixedSize(true);
        menuHomeBinding.rvWaterFallsFlow.setNestedScrollingEnabled(false);
        menuHomeBinding.rvWaterFallsFlow.setFocusable(false);

要点:确定RecyclerView的高度

完整代码:
XML:请忽略无用的代码,只要看最外层NestedScrollView和最下面的RecyclerView就OK

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <data>

    </data>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <!-- Banner -->
            <androidx.viewpager.widget.ViewPager
                android:id="@+id/vp_home_menu_banner"
                android:layout_width="match_parent"
                android:layout_height="160dp"
                android:layout_marginStart="10dp"/>
            <!--   功能菜单     -->
            <LinearLayout
                android:id="@+id/ll_home_menu"
                android:layout_width="match_parent"
                android:layout_height="90dp"
                android:layout_marginHorizontal="16dp"
                android:layout_marginTop="10dp"
                android:orientation="horizontal">

                <LinearLayout
                    android:id="@+id/ll_home_menu_reservation"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_marginEnd="16dp"
                    android:layout_weight="1"
                    android:background="@drawable/style_constraintlayout_purple_gradient_bg"
                    android:gravity="center"
                    android:orientation="vertical">

                    <androidx.cardview.widget.CardView
                        android:id="@+id/cv_menu_home_reservation"
                        android:layout_width="match_parent"
                        android:layout_height="60dp"
                        android:layout_marginHorizontal="6dp"
                        android:layout_marginTop="4dp"
                        app:cardCornerRadius="8dp"
                        app:cardElevation="0dp">

                        <ImageView
                            android:layout_width="60dp"
                            android:layout_height="match_parent"
                            android:layout_gravity="center"
                            android:scaleType="centerInside"
                            android:src="@drawable/home_menu_reservation" />
                    </androidx.cardview.widget.CardView>

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="20dp"
                        android:layout_marginTop="2dp"
                        android:layout_marginBottom="4dp"
                        android:gravity="center"
                        android:text="@string/homeMenuReservation"
                        android:textColor="@color/white" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/ll_home_menu_group"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_marginStart="8dp"
                    android:layout_marginEnd="16dp"
                    android:layout_weight="1"
                    android:background="@drawable/style_constraintlayout_blue_gradient_bg"
                    android:gravity="center"
                    android:orientation="vertical">

                    <androidx.cardview.widget.CardView
                        android:id="@+id/cv_menu_home_group"
                        android:layout_width="match_parent"
                        android:layout_height="60dp"
                        android:layout_marginHorizontal="6dp"
                        android:layout_marginTop="4dp"
                        app:cardCornerRadius="8dp"
                        app:cardElevation="0dp">

                        <ImageView
                            android:layout_width="60dp"
                            android:layout_height="match_parent"
                            android:layout_gravity="center"
                            android:scaleType="centerInside"
                            android:src="@drawable/home_menu_group" />
                    </androidx.cardview.widget.CardView>

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="20dp"
                        android:layout_marginTop="2dp"
                        android:layout_marginBottom="4dp"
                        android:gravity="center"
                        android:text="@string/homeMenuGroup"
                        android:textColor="@color/white" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/ll_home_menu_unpack"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_marginStart="8dp"
                    android:layout_marginEnd="16dp"
                    android:layout_weight="1"
                    android:background="@drawable/style_constraintlayout_orange_gradient_bg"
                    android:gravity="center"
                    android:orientation="vertical">

                    <androidx.cardview.widget.CardView
                        android:id="@+id/cv_menu_home_unpack"
                        android:layout_width="match_parent"
                        android:layout_height="60dp"
                        android:layout_marginHorizontal="6dp"
                        android:layout_marginTop="4dp"
                        app:cardCornerRadius="8dp"
                        app:cardElevation="0dp">

                        <ImageView
                            android:layout_width="60dp"
                            android:layout_height="match_parent"
                            android:layout_gravity="center"
                            android:scaleType="centerInside"
                            android:src="@drawable/home_menu_unpack" />
                    </androidx.cardview.widget.CardView>

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="20dp"
                        android:layout_marginTop="2dp"
                        android:layout_marginBottom="4dp"
                        android:gravity="center"
                        android:text="@string/homeMenuUnpack"
                        android:textColor="@color/white" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/ll_home_menu_game"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_marginStart="8dp"
                    android:layout_weight="1"
                    android:background="@drawable/style_constraintlayout_red_gradient_bg"
                    android:gravity="center"
                    android:orientation="vertical">

                    <androidx.cardview.widget.CardView
                        android:id="@+id/cv_menu_home_game"
                        android:layout_width="match_parent"
                        android:layout_height="60dp"
                        android:layout_marginHorizontal="6dp"
                        android:layout_marginTop="4dp"
                        app:cardCornerRadius="8dp"
                        app:cardElevation="0dp">

                        <ImageView
                            android:layout_width="60dp"
                            android:layout_height="match_parent"
                            android:layout_gravity="center"
                            android:scaleType="centerInside"
                            android:src="@drawable/home_menu_game" />
                    </androidx.cardview.widget.CardView>

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="20dp"
                        android:layout_marginTop="2dp"
                        android:layout_marginBottom="4dp"
                        android:gravity="center"
                        android:text="@string/homeMenuGame"
                        android:textColor="@color/white" />
                </LinearLayout>

                <TextView
                    android:id="@+id/tv_home_menu_gourmet"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:drawableTop="@mipmap/ic_home_menu_gourmet"
                    android:drawablePadding="3dp"
                    android:gravity="center"
                    android:text="@string/homeMenuGourmet"
                    android:visibility="gone" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/lightGray"
                android:nestedScrollingEnabled="false"
                android:orientation="vertical">
                <!-- 秒杀 -->
                <androidx.constraintlayout.widget.ConstraintLayout
                    android:id="@+id/cl_home_spike"
                    android:layout_width="match_parent"
                    android:layout_height="120dp"
                    android:layout_marginHorizontal="16dp"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/style_linearlayout_round">

                    <TextView
                        android:id="@+id/tv_home_spike"
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:background="@drawable/style_textview_horizontal_gradient_round_top"
                        android:gravity="start|center_vertical"
                        android:paddingStart="16dp"
                        android:paddingEnd="10dp"
                        android:text="@string/homeSpike"
                        android:textColor="@color/white"
                        android:textSize="16sp"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

                    <androidx.cardview.widget.CardView
                        android:id="@+id/cv_home_spike_img"
                        android:layout_width="80dp"
                        android:layout_height="80dp"
                        android:layout_gravity="center"
                        android:layout_marginStart="20dp"
                        app:cardCornerRadius="8dp"
                        app:cardElevation="0dp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toStartOf="@id/ll_home_spike"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@id/tv_home_spike">

                        <ImageView
                            android:layout_width="match_parent"
                            android:layout_height="80dp"
                            android:src="@drawable/test_1" />
                    </androidx.cardview.widget.CardView>

                    <LinearLayout
                        android:id="@+id/ll_home_spike"
                        android:layout_width="0dp"
                        android:layout_height="60dp"
                        android:orientation="vertical"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintHorizontal_weight="1"
                        app:layout_constraintStart_toEndOf="@+id/cv_home_spike_img"
                        app:layout_constraintTop_toBottomOf="@id/tv_home_spike">

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="30dp"
                            android:gravity="start|center_vertical"
                            android:paddingStart="20dp"
                            android:text="00000000"
                            android:textColor="@color/deepTextColor"
                            android:textSize="16sp" />

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="30dp"
                            android:gravity="start|center_vertical"
                            android:paddingStart="20dp"
                            android:text="111111111111" />
                    </LinearLayout>

                    <TextView
                        android:id="@+id/tv_home_spike_discount_price"
                        android:layout_width="wrap_content"
                        android:layout_height="30dp"
                        android:gravity="center"
                        android:paddingStart="20dp"
                        android:text="¥99.00"
                        android:textColor="@color/crimson"
                        app:layout_constraintStart_toEndOf="@id/cv_home_spike_img"
                        app:layout_constraintTop_toBottomOf="@id/ll_home_spike" />

                    <TextView
                        android:id="@+id/tv_home_spike_price"
                        android:layout_width="wrap_content"
                        android:layout_height="30dp"
                        android:gravity="start|center_vertical"
                        android:paddingStart="20dp"
                        android:text="¥199.00"
                        android:textColor="@color/grey"
                        app:layout_constraintStart_toEndOf="@id/tv_home_spike_discount_price"
                        app:layout_constraintTop_toBottomOf="@id/ll_home_spike" />

                </androidx.constraintlayout.widget.ConstraintLayout>
                <!-- 优惠券 -->
                <androidx.constraintlayout.widget.ConstraintLayout
                    android:id="@+id/cl_home_coupon"
                    android:layout_width="match_parent"
                    android:layout_height="140dp"
                    android:layout_marginHorizontal="16dp"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/style_linearlayout_round">

                    <TextView
                        android:id="@+id/tv_menu_home_coupon_list"
                        android:layout_width="match_parent"
                        android:layout_height="35dp"
                        android:background="@drawable/style_textview_horizontal_gradient_round_top"
                        android:gravity="start|center_vertical"
                        android:paddingStart="16dp"
                        android:text="@string/menuHomeCouponList"
                        android:textColor="@color/white"
                        android:textSize="16sp"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

                    <TextView
                        android:id="@+id/tv_menu_home_coupon_seller1"
                        android:layout_width="0dp"
                        android:layout_height="30dp"
                        android:gravity="center"
                        android:text="每满1000减100元"
                        android:textColor="@color/crimson"
                        app:layout_constraintBottom_toTopOf="@id/tv_menu_home_description1"
                        app:layout_constraintEnd_toStartOf="@id/tv_menu_home_coupon_seller2"
                        app:layout_constraintHorizontal_weight="1"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@id/tv_menu_home_coupon_list" />

                    <TextView
                        android:id="@+id/tv_menu_home_description1"
                        android:layout_width="0dp"
                        android:layout_height="30dp"
                        android:gravity="center"
                        android:text="仅可购买部分品类商品"
                        app:layout_constraintEnd_toStartOf="@id/tv_menu_home_description2"
                        app:layout_constraintHorizontal_weight="1"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@id/tv_menu_home_coupon_seller1" />

                    <Button
                        android:id="@+id/btn_menu_home_coupon1"
                        android:layout_width="100dp"
                        android:layout_height="28dp"
                        android:layout_marginStart="40dp"
                        android:background="@drawable/style_coupon_button_round"
                        android:text="@string/menuHomeCouponReceive"
                        android:textColor="@color/crimson"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toStartOf="@id/tv_menu_home_coupon_dividing_line"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@id/tv_menu_home_description1" />

                    <TextView
                        android:id="@+id/tv_menu_home_coupon_dividing_line"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_marginHorizontal="-40dp"
                        android:background="@drawable/style_dividing_line_vertical"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toStartOf="@id/tv_menu_home_coupon_seller2"
                        app:layout_constraintStart_toEndOf="@id/tv_menu_home_coupon_seller1"
                        app:layout_constraintTop_toBottomOf="@id/tv_menu_home_coupon_list" />

                    <TextView
                        android:id="@+id/tv_menu_home_coupon_seller2"
                        android:layout_width="0dp"
                        android:layout_height="30dp"
                        android:gravity="center"
                        android:text="每满1000减100元"
                        android:textColor="@color/crimson"
                        app:layout_constraintBottom_toTopOf="@id/tv_menu_home_description2"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintHorizontal_weight="1"
                        app:layout_constraintStart_toEndOf="@id/tv_menu_home_coupon_seller1"
                        app:layout_constraintTop_toBottomOf="@id/tv_menu_home_coupon_list" />

                    <TextView
                        android:id="@+id/tv_menu_home_description2"
                        android:layout_width="0dp"
                        android:layout_height="30dp"
                        android:gravity="center"
                        android:text="仅可购买部分品类商品"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintHorizontal_weight="1"
                        app:layout_constraintStart_toEndOf="@id/tv_menu_home_description1"
                        app:layout_constraintTop_toBottomOf="@id/tv_menu_home_coupon_seller2" />

                    <Button
                        android:id="@+id/btn_menu_home_coupon2"
                        android:layout_width="100dp"
                        android:layout_height="28dp"
                        android:layout_marginEnd="40dp"
                        android:background="@drawable/style_coupon_button_round"
                        android:text="@string/menuHomeCouponReceive"
                        android:textColor="@color/crimson"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toEndOf="@id/tv_menu_home_coupon_dividing_line"
                        app:layout_constraintTop_toBottomOf="@id/tv_menu_home_description2" />

                </androidx.constraintlayout.widget.ConstraintLayout>
                <!-- 瀑布流 -->
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rv_water_falls_flow"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginHorizontal="16dp"
                    android:layout_marginTop="10dp" />
            </LinearLayout>
        </LinearLayout>
    </androidx.core.widget.NestedScrollView>

</layout>

Fragment:同样请忽略无用逻辑

package com.qingnuo.yami.view.home;

import android.content.Context;
import android.content.Intent;
import android.database.Observable;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ObservableField;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;

import java.util.ArrayList;
import java.util.List;

/**
 * 首页横向菜单首页
 */
public class HomeMenuFragment extends Fragment implements View.OnClickListener {
    private static final String TAG = "HomeMenuFragment";
    private FragmentMenuHomeBinding menuHomeBinding;
    private Context mContext;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        menuHomeBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_menu_home, container, false);
        mContext = getContext();
        initView();
        return menuHomeBinding.getRoot();
    }

    private void initView() {

        //设置Adapter
        HomeWaterFallsFlowAdapter waterFallsFlowAdapter = new HomeWaterFallsFlowAdapter(mContext);
        waterFallsFlowAdapter.setList(waterFallsFlowBeanArrayList);
        menuHomeBinding.rvWaterFallsFlow.setAdapter(waterFallsFlowAdapter);
        // 计算需要高度
        ViewGroup.LayoutParams layoutParams = menuHomeBinding.rvWaterFallsFlow.getLayoutParams();
        int height = 0;
        for (int i = 0; i < waterFallsFlowBeanArrayList.size(); i++) {
            if (i % 2 == 0) {
                height += 400;
            } else if (i % 3 == 0) {
                height += 360;
            } else {
                height += 440;
            }
        }
        layoutParams.height = height - waterFallsFlowBeanArrayList.size() * 100;
        menuHomeBinding.rvWaterFallsFlow.setLayoutParams(layoutParams);
        menuHomeBinding.rvWaterFallsFlow.setHasFixedSize(true);
        menuHomeBinding.rvWaterFallsFlow.setNestedScrollingEnabled(false);
        menuHomeBinding.rvWaterFallsFlow.setFocusable(false);

    }

}

参考
NestedScrollView嵌套RecyclerView无法正常显示
NestedScrollView的使用
解决嵌套显示不全
嵌套不显示问题

Android番外篇 NestedScrollView嵌套RecyclerView (1)使用NestedScrollView嵌套RecyclerView时,滑动lRecyclerView列表会出现强烈的卡顿感 解决方式:setNestedScrollingEnabled()方法 //启用嵌套滚动 mRecyclerView.setNestedScrollingEnabled(false); 源码解析 public class RecyclerView extends ViewGroup implements ScrollingView, NestedScrollingChild { . 阅读详情

相关推荐

解决ScrollView中嵌套RecyclerVIew产生滑动冲突问题

实现某个功能时发现RecyclerView总是先获取焦点,然后在ScrollView中滑动,为了让ScrollVoiew先滑动,我尝试了网上一些博客所说的方法,有些博主能成功,而我的却啊还是不行,具体列出尝试的几种方法: 1. 在ScrollView中添加属性(已经设有属性android:fillViewport="true"): android:focusable="true" andro...

fangchuli的博客 5347

面试题:事务嵌套调用不起作用原因以及解决方案

问题:Controller层有一个方法,调用service层的methodA方法,methodA方法调用同类中的methodB方法,前提是methodA方法未加事务,methodB方法有加事务,里面有插入和修改两个方法,问如果methodB方法里面发生异常,事务是否起作用 答案:事务不起作用 分析: @Transactional是基于动态代理的方式给sql加事务,当容器扫描到这个注解的时候,会给该注解所在的类创建一个代理类 ​​​​​​​它会给带有注解的那个方法的前面开启事务,当我们通过A方法调用B方

weixin_40576390的博客 978

ScrollView嵌套RecyclerView滑动冲突相关问题

出现了滑动冲突问题,主要表现为横向RecyclerView滑动不灵敏,纵向RecyclerView滑动卡顿。 scrollview里面放Recyclerview 会导致view不回收,内存压力大; 最好使用 Recyclerview通过Item不同layout实现里面放两个横向的Recyclerview 二、问题分析 1.横向RecyclerView滑动不灵敏 针对该问题,解决的方案是根据当前滑动...

大叔啊 1711

NestedScrollView嵌套RecyclerView

开发过程中NestedScrollView替代了ScrollView,RecyclerView代替了ListView   有了NestedScrollView解决嵌套滑动的问题就简单的多了,嵌套滑动可能出现两个问题 1、使用NestedScrollView嵌套RecyclerView时,滑动lRecyclerView列表会出现卡顿感 2、使用NestedScrollView嵌套Recycl...

anyudong123的博客 1755

Android开发:ScrollView嵌套RecyclerView滑动冲突的5种解决方案(附完整代码)

本文深入剖析了Android开发中ScrollView嵌套RecyclerView时产生滑动冲突的技术根源,并系统性地提供了五种实战解决方案。从完全禁用子视图滚动、动态计算高度,到使用NestedScrollView并禁用嵌套滚动、自定义事件处理逻辑,以及固定布局高度,每种方案均附有完整代码和适用场景分析,帮助开发者根据具体需求选择最优的滑动处理方案。

weixin_29228781的博客 555

Android开发中ScrollView嵌套ListView的解决方案汇总

定义了子控件如何向父容器请求滚动的能力。:定义了父容器如何响应子控件的滚动请求。当子控件(如)开始滚动时,它会通过方法向父容器(如)申请滚动权限。父容器在收到申请后,可以决定是否参与滚动事件的处理,并通过和方法与子控件进行协调。<TextViewandroid:text="欢迎来到我的页面"<ImageView<TextViewandroid:text="数据项内容"@Override@Override@Override@Override。

weixin_29050829的博客 1241

深入解析NestedScrollView嵌套RecyclerView的滑动冲突与性能优化

本文深入解析了Android开发中NestedScrollView嵌套RecyclerView时常见的滑动冲突与性能问题。通过分析滑动卡顿的根本原因,提供了关闭RecyclerView嵌套滚动(setNestedScrollingEnabled(false))这一核心解决方案,并探讨了由此引发的焦点抢占、一次性测量等性能隐患。文章进一步给出了固定高度、使用ConcatAdapter等优化策略,帮助开发者构建流畅的嵌套滚动界面。

echo99的专栏 1028

NestedScrollView与RecyclerView嵌套,导致RecyclerView无法复用,滑动冲突等问题

NestedScrollView与RecyclerView嵌套,导致RecyclerView无法复用,滑动冲突等问题

解决ScrollView嵌套RecyclerView出现item显示不全的问题

最近开发遇到需要布局底部有个列表需要滑动,原本打算在RecyclerView中添加HeadView,后来觉得不太合适,就采用了ScrollView嵌套RecyclerView方式来实现,在Android6.0以下的手机都可以使用,当时也没太在意觉得能实现就好了 ScrollView嵌套RecyclerView滑动冲突解决: 禁止RecyclerView滑动,在RecyclerView的Linear...

lplj717的博客 3054

1.2 从“跟网”到“构网”:技术范式的历史性转变

新型电力系统面临"双高"特征带来的稳定性挑战,促使并网控制技术从"跟网型"向"构网型"范式转变。传统跟网型变流器作为受控电流源依赖强电网,存在短路电流能力有限、易失稳等缺陷;而构网型变流器模拟同步发电机特性,作为受控电压源具备自主建立电压/频率、提供虚拟惯性、增强短路容量和改善系统阻尼四大核心能力。这一技术范式转变使变流器从电网跟随者变为构建支撑者,成为解决新能源大规模接入稳定性的关键。

技术工作者 722

YOLOv8傻瓜式教程

YOLOv8傻瓜式教程,附带详细参数配置。

Father_of_Python的博客 1万+

NestedScrollView中嵌套recyclerView的焦点问题

思路:一开始认为是adapter刷新数据,调用notifyDataSetChanged的时候获取了焦点,所以显示为置顶,那我就在刷新数据后延时1.5秒在去设置nestedScrollView滑动到底部。即调用下面: ScrollView.fullScroll(View.FOCUS_UP); 然并软。 后来神奇的觉得,会不会是滑动冲突了,于是又在xml文件的recyclerView...

CHZKAL的博客 2445

实战指南:如何用Frida绕过某梆加固的Anti-Frida检测(附完整脚本)

本文深入剖析了企业级加固方案中的Anti-Frida检测机制,并提供了实战对抗策略。通过分析基于文件系统、内存特征、行为及环境的多层次检测原理,文章详细介绍了如何定位检测逻辑、绕过maps文件扫描、对抗内存与行为特征检测,并附上了针对某梆加固的完整绕过脚本与系统化工程方案。

weixin_42527589的博客 600

ScrollView嵌套RecyclerView滚动冲突

ScrollView嵌套RecyclerView滚动冲突1. 概述2.布局3.MainActivity 1. 概述 使用ScrollView嵌套RecyclerView会造成滚动冲突。这个问题可以使用NestedScrollView来解决。 2.布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" andro

weixin_40763897的博客 2178

从FreeCAD到BIMBase:PlaneGCS约束求解器的移植使用指南

本文为BIMBase平台的开发者提供了一份详细的PlaneGCS几何约束求解器移植与集成指南。文章深入探讨了如何从FreeCAD中提取PlaneGCS核心代码,并将其适配到BIMBase的C++二次开发环境中,重点解决了内存管理、数据模型桥接、约束抽象以及性能调优等关键问题,旨在帮助开发者构建稳定高效的参数化设计模块。

weixin_29213525的博客 320

高等数学/概率论/数理统计/线性代数/离散数学面试-核心概念-问题理解

特征值与特征向量是线性代数中的概念,它们与线性变换有关。在线性变换中,如果存在非零向量 v ,使得当该向量通过变换后,其方向不变,只是长度发生了变化,那么这个向量 v 就是特征向量。而这个长度变化的比例因子,即变换前后向量长度的比值,称为特征值。数学公式表示:通俗易懂的解释:想象一下,你有一个可以伸缩的橡皮筋,这个橡皮筋可以代表一个向量。现在,你有一个特殊的机器,它可以改变橡皮筋的形状,但不会改变它延伸的方向。当你把橡皮筋放入机器中,机器会拉伸或压缩橡皮筋,但橡皮筋的方向保持不变。

m0_64198455的博客 2292

ScrollView 嵌套 RecyclerView 冲突问题

开发中使用ScrollView 嵌套 RecyclerView 时遇到了滑动冲突和显示不全问题。自己尝试解决了一下。 由于项目需求,需要 ScrollView 高度是 wrap_content,ScrollView 内是一个 LinearLayout ,LinearLayout 里添加了多个 RecyclerView 。SrcollView 有一个最大高度 maxHeight 。 对于可能出现的 ...

wandryoung的博客 662

Transformer 面试题及详细答案120道(1-10)-- 基础概念

本文总结了Transformer模型的10个常见面试问题及答案,涵盖了其核心结构、创新点、工作机制等关键知识点。主要内容包括:Transformer的自注意力机制和多头注意力机制创新点,相比RNN/CNN的优势,模型在《Attention Is All You Need》论文中的提出背景,以及Encoder-Decoder协同工作流程等。重点解析了位置编码的作用、长距离依赖处理能力、与传统注意力机制的区别等核心问题。每个问题都给出了简明扼要的专业解答,适合作为Transformer相关面试准备的参考资料。

大剑师兰特的GIS世界 849

NestedScrollView和ScrollView常见问题总结

NestedScrollView和ScrollView常见问题总结

唐诺 6265

手把手教你学Simulink——基础储能管理场景实例:基于Simulink的压缩空气储能(CAES)系统简化模型仿真

本文介绍了基于Simulink的压缩空气储能(CAES)系统简化模型仿真方法。CAES作为大规模长时储能方案,相比锂电池具有成本低、寿命长等优势。文章详细讲解了AA-CAES系统组成、热力学建模理论,以及Simulink实现流程,包括储气室、压缩机、膨胀机等核心模块的建模方法。通过8小时充电(50MW)和6小时放电(40MW)的仿真,验证了系统可实现60%往返效率。该模型为理解CAES系统运行机制提供了实用工具,并指出热管理、储气室特性等工程实践要点,为新型电力系统储能规划提供了仿真基础。

MHD0815的博客 171

人工智能技术基础系列之:迁移学习

作者:禅与计算机程序设计艺术 1.背景介绍 随着深度学习和神经网络的快速发展,越来越多的应用场景需要处理大量的数据和复杂的任务。然而,由于计算资源、存储空间等条件的限制,传统的人工智能方法往往不能满足实际需求。因此,为了提高效率和降低成本,研究人员提出了迁移学习的概念。本篇文章将详细介绍迁移学习的基

AI天才研究院 698

ScrollView嵌套RecyclerView的几个坑

第一种解决方式: 当ScrollView与RecyclerView嵌套使用时遇到的几个坑 1、6.0及以上系统RecyclerView显示不全 2、滑动冲突,不流畅 3、页面切换导致嵌套布局不显示在顶部,而是显示RecyclerView的第一个item 1.显示不全 使用RelativeLayout将RecyclerView嵌套 <RelativeLa...

qq_35657482的博客 1594

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

NestedScrollView RecycleView 嵌套 滑动冲突

NestedScrollView RecycleView 滑动 冲突

wojiaomtaa的博客 4496

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Android ScrollView嵌套RecyclerView 导致RecyclerView数据展示不全问题

异常表现:RecyclerView绑定的数据源数量(日志确认正确)与界面显示数量不一致,且显示条数随数据量随机变化(3 条显 2 条、4 条显 1 条、5 条显 3 条),仅部分数据能展示。布局初始结构:外层用ScrollView包裹包含两个CustomBlogCardView(内部均含RecyclerView)的LinearLayout。关键修复动作:将外层ScrollView替换为NestedScrollView后,所有数据均能完整显示,问题彻底解决。

y515278178的博客 811

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

解决ScrollView 和 RecyclerView 嵌套问题

问题一:ScrollView嵌套RecyclerView显示不完全 这个问题应该都遇到过,我之前就被这个问题搞的崩溃了,网上搜的解决方法都是重写LinearLayoutManager,有人说有效,但在我这没用,我也不知道那些方法是不是真的有效,但还是在最下边把这个方法贴出来吧,万一对你有用呢。 真正解决我问题的是另一个方法,不用重写什么布局管理器,只要将嵌套在外层的ScrollView的宽、高均设置为match_parent,然后在ScrollView的布局中加入一句话(必须): ...

陈立的博客 1183
上一篇: Android自定义View 简单拖拽实现(一)
下一篇: Android通过Glide获取网络图片尺寸
是阿秋吖
博客等级 码龄10年 7粉丝 33原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值