List View Not Scrolling In Fragment Using View Pager Inside Nestedscrollview
Hi there i needed to create layout like whatsapp, which scrolls the actionbar but not tabLayout. I used viewpager for loads fragment in it. In fragment i added listview but on List
Solution 1:
Okey first of all You warped ViewPager
inside NestedScrollView
, this is not necessary.
so change,
<android.support.v4.widget.NestedScrollViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_marginTop="?attr/actionBarSize"app:layout_behavior="@string/appbar_scrolling_view_behavior"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:minHeight="1000dp"android:orientation="vertical"><android.support.v4.view.ViewPagerandroid: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
publicclassNonScrollListViewextendsListView {
publicNonScrollListView(Context context) {
super(context);
}
publicNonScrollListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
publicNonScrollListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@OverridepublicvoidonMeasure(int widthMeasureSpec, int heightMeasureSpec) {
intheightMeasureSpec_custom= MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
ViewGroup.LayoutParamsparams= getLayoutParams();
params.height = getMeasuredHeight();
}
}
And just change your fragment_one liske this.
<android.support.v4.widget.NestedScrollViewxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><packagename.NonScrollListViewandroid: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..
Solution 2:
you can use Observable scrollview Refer the link
Post a Comment for "List View Not Scrolling In Fragment Using View Pager Inside Nestedscrollview"