Viewpager in a Nestedscrollview

How to use viewpager inside nestedScrollView with a view top of viewpager

So I have finally resolved this problem by just creating Custom Viewpager as mentioned here: Custom ViewPager that calculate ViewPager height and setNestedScrollingEnable(false) to RecyclerView inside Viewpager. By setting NestedScrollingEnalbe = false Recyclerview does set parent NestedScrollView's scroll. So Parent NestedScrollView works with inside Viewpager.

Fragment (Viewpager) inside NestedScrollView not loading

Try this

NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.userProfile_NestedScrollView);
scrollView.setFillViewport (true);

Multiple NestedScrollViews inside ViewPager not scrolling

Had a 20 minute break and solved it immediately. The ViewPager needs nested scrolling enabled, either via xml android:nestedScrollingEnabled="true" or programatically via ViewCompat.setNestedScrollingEnabled(viewPager, true) (>= API 21 only)

Unable to Put ViewPager inside a ScrollVIew/NestedScrollView

I solved the issue by fixing the height of my ViewPager like :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
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:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context=".activities.HomeActivity">

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

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:onClick="pagerClick"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="top"/>

...

</LinearLayout>

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

Android NestedScrollView doesn't work in layout with viewpager

As you know NestedScrollView has one child and the height of his child must be wrap_content if you want scroll behavior for your layout.

In your first layout, you must set the height of your ConstraintLayout to wrap_content but if you want your layout to be match_parent for whatever reason (such as you want to bound your ViewPager in the bottom of your layout) you must use suggested answer(it means you must use CoordinatorLayout) but with the following consideration:

1- You should put all your stuff you want to scroll in the AppbarLayout.This layout extended from LinearLayout so you can easily put your stuff into it. from your question, I think you want to scroll all stuff above your ViewPager but you may change it as you want.

(Note: actually, I recommend using CollapsingToolbar as a child of your AppbarLAyout and then put your stuff into it but for your question, this is work perfectly too)

2- Add app:layout_scrollFlags="scroll" attribute in the root of your stuff within your AppbarLayout

3- Add app:layout_behavior="@string/appbar_scrolling_view_behavior" attribute to the sibling of your AppbarLayout. In your question, you use this attribute in your NestedScrollView.

This is my code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<androidx.appcompat.widget.Toolbar
app:layout_scrollFlags="scroll"//I forget too add this, so I edit my answer
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme" />

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll"
android:orientation="vertical">

<View
android:id="@+id/profile_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/description"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="@dimen/spacing_normal"
android:layout_marginLeft="@dimen/spacing_normal"
android:layout_marginEnd="@dimen/spacing_normal"
android:layout_marginRight="@dimen/spacing_normal"
app:layout_constraintBottom_toBottomOf="@+id/profile_image"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/profile_image"
app:layout_constraintTop_toTopOf="@+id/profile_image"
tools:text="Short description " />

<include
layout="@layout/qff_layout"
android:id="@+id/qff_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_image" />

<com.google.android.material.tabs.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#559735"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/qff_layout"
app:tabMode="fixed" />

</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.AppBarLayout>

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/sliding_tabs" />
</androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

I didn't try this code but I'm pretty sure this is work for you :)



Related Topics



Leave a reply



Submit