NestedScrollView与RecyclerView嵌套,以及NestedScrollView不会滚动到屏幕顶部解决

①NestedScrollView与RecyclerView嵌套,导致滚动惯性消失

解决:mRecyclerView.setNestedScrollingEnabled(false);


②NestedScrollView中嵌套其他布局和RecyclerView后,不会滚动到屏幕顶部

解决给最顶部的布局View设置下requestFocus();

xml version="1.0" encoding="utf-8"?>
    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"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical">

            android:id="@+id/swipe"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

                    android:id="@+id/src"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:focusable="true"
            android:focusableInTouchMode="true">


                            android:id="@+id/ll_valuation_start"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">


                                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:src="@drawable/ic_launcher_background"/>

                                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="信用可也换钱花"
                    android:textColor="@android:color/black"
                    android:textSize="16sp"/>

                                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="6dp"
                    android:text="自营贷款产品,无需审核,立即放款"
                    android:textColor="@android:color/black"/>

                
                    android:id="@+id/rv"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    >
                

            

        
    


如果里面ScrollView里面有连个RecyclerView则都要是设置 mRecyclerView.setNestedScrollingEnabled(false);

你可能感兴趣的:(Android)