天天看点

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">           

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:text="已售罄"
                    android:textColor="#FF333333"
                    android:textSize="14sp" />



            <android.support.v7.widget.RecyclerView
                android:id="@+id/rv_sold_out"
                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设置:

继续阅读