NestedScrollView fragment覆盖部分RecycleView

当NestedScrollView内包含RecycleView和Fragment时,可能出现Fragment遮挡RecycleView部分数据的问题。解决方法是将子View的margin替换为padding,避免布局重叠。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

NestedScrollView 里面包含RecycleView和Fragment,在加载数据后,后加载的Fragment覆盖了部分RecycleView数据。
原因是NestedScrollView 子View设置了margintop和marginbottom,改成padding就可以了
问题代码 :

 <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        android:fillViewport="true"
        android:overScrollMode="never">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:descendantFocusability="blocksDescendants"
            android:focusableInTouchMode="true"
            android:focusable="true"
            android:layout_marginBottom="@dimen/dp16"
            android:paddingLeft="@dimen/dp12"
            android:paddingRight="@dimen/dp12">

            <androidx.recyclerview.widget.RecyclerView               
                android:layout_width="match_parent"
                android:nestedScrollingEnabled="false"
                android:layout_height="wrap_content"/>

            <FrameLayout           
                android:layout_marginTop="@dimen/dp16"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

            <FrameLayout               
                android:layout_marginTop="@dimen/dp16"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
        </LinearLayout>

    </androidx.core.widget.NestedScrollView>

修改后

<androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        android:fillViewport="true"
        android:overScrollMode="never">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:descendantFocusability="blocksDescendants"
            android:focusableInTouchMode="true"
            android:focusable="true"
            android:paddingTop="@dimen/dp16"
            android:paddingBottom="@dimen/dp20"
            android:paddingLeft="@dimen/dp12"
            android:paddingRight="@dimen/dp12">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rv_employed"
                android:layout_width="match_parent"
                android:nestedScrollingEnabled="false"
                android:layout_height="wrap_content"/>

            <FrameLayout
                android:id="@+id/fl_all_employed"
                android:layout_marginTop="@dimen/dp16"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

            <FrameLayout
                android:id="@+id/fl_other_employed"
                android:layout_marginTop="@dimen/dp16"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
        </LinearLayout>

    </androidx.core.widget.NestedScrollView>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值