List view not scrolling in fragment using view pager inside NestedScrollView

空扰寡人 提交于 2019-12-03 08:27:32

Okey first of all You warped ViewPager inside NestedScrollView, this is not necessary.

so change,

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="?attr/actionBarSize"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="1000dp"
        android:orientation="vertical">

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

to,

<android.support.v4.view.ViewPager
     android:id="@+id/pager"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_weight="1"
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

Now Your are taking ListView, which is not working good with AppBarLayout, so I suggest you use RecyclerView instead.

Note: if you still want to use ListView you can use NonScrollListview wraping it under NestedScrollView.

NonScrollListView

public class NonScrollListView extends ListView {

    public NonScrollListView(Context context) {
         super(context);
    }

    public NonScrollListView(Context context, AttributeSet attrs) {
         super(context, attrs);
    }

    public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
         super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
         ViewGroup.LayoutParams params = getLayoutParams();
         params.height = getMeasuredHeight();
    }
}

And just change your fragment_one liske this.

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <packagename.NonScrollListView
        android:id="@+id/listTest"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></packagename.NonScrollListView>
</android.support.v4.widget.NestedScrollView>

I hope this will help you out. Happy coding..

you can use Observable scrollview Refer the link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!