天天看點

解決NestedScrollView 嵌套ViewPager、RecyclerView問題解決NestedScrollView 嵌套ViewPager、RecyclerView問題

解決NestedScrollView 嵌套ViewPager、RecyclerView問題

布局:

<android.support.v4.widget.NestedScrollView
        android:id="@+id/nsv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

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

                

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

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

問題:

ViewPager無法翻頁: 

NestedScrollView設定 

android:fillViewport=”true”

防止卡頓:

LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(horizontal);
        manager.setSmoothScrollbarEnabled(true);
        manager.setAutoMeasureEnabled(true);
        rv.setLayoutManager(manager);
        rv.setHasFixedSize(true);
        rv.setNestedScrollingEnabled(false);
           

防止位置錯亂:

NestedScrollView的第一個Child設定:

android:descendantFocusability="blocksDescendants"
           

繼續閱讀