Reputation: 27
NestedScrollView is not working with ViewPager
Here is my code. Can you please suggest or help me. when i try NestedScrollView without ViewPager its working on other page. here is my layout file.
this RelativeLayout can be removed if needed as i have added this
<RelativeLayout 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"
android:background="#ffffff"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorAccent">
<ImageView
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/back"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="मेरी प्रोफाइल"
android:textColor="#ffffff"
android:textSize="17sp"
android:layout_centerInParent="true"/>
</RelativeLayout>
NestedScrollView is used
<androidx.core.widget.NestedScrollView
android:id="@+id/nest_scrollview"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:nestedScrollingEnabled="true"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="true"
>
<com.test.utils.RoundedImageView
android:id="@+id/iv_user_image"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:src="@drawable/uploadphoto"
android:tint="@color/colorPrimary"
android:layout_margin="10dp"/>
<TextView
android:id="@+id/tv_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@+id/iv_user_image"
app:layout_constraintLeft_toRightOf="@+id/iv_user_image"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:textColor="@color/black"
android:textSize="18sp"
android:textAlignment="center"
android:text="Hitesh"/>
<TextView
android:id="@+id/tv_user_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/tv_user_name"
app:layout_constraintLeft_toRightOf="@+id/iv_user_image"
android:textAlignment="center"
android:layout_marginTop="5dp"
android:layout_marginLeft="20dp"
android:textColor="@color/quantum_orange"
android:textSize="15sp"/>
<TextView
android:id="@+id/tv_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/iv_user_image"
app:layout_constraintLeft_toLeftOf="@+id/iv_user_image"
android:layout_marginTop="20dp"
android:textColor="@color/black"
android:drawableLeft="@drawable/gglocation"
android:text="Hitesh"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_referral"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/tv_address"
android:background="@drawable/border_home_blue"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:padding="5dp">
<ImageView
android:id="@+id/iv_referral"
android:layout_width="15dp"
android:layout_height="15dp"
android:src="@drawable/ic_trophy"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:id="@+id/tv_referral_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/iv_referral"
android:textColor="@color/black"
android:layout_marginLeft="5dp"
android:textAllCaps="true"
android:gravity="center"
android:textSize="18sp"
android:text="Hitesh"/>
<TextView
android:id="@+id/tv_hint"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/tv_referral_code"
app:layout_constraintRight_toLeftOf="@+id/iv_whatsapp"
android:layout_margin="10dp"
android:textAllCaps="true"
android:textSize="12sp"
android:text="अपना रेफरल कोड शेयर करे"/>
<ImageView
android:id="@+id/iv_whatsapp"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/ic_whatsapp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.cardview.widget.CardView
android:id="@+id/rateus"
app:cardCornerRadius="6dp"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
app:layout_constraintTop_toBottomOf="@+id/cl_referral"
app:layout_constraintLeft_toLeftOf="parent"
android:nestedScrollingEnabled="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_centerVertical="true"
android:src="@drawable/rateus"
/>
</androidx.cardview.widget.CardView>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/rateus"
app:tabSelectedTextColor="@color/colorPrimary"
app:tabTextColor="@color/black"
app:tabIndicatorColor="@color/colorPrimary"
android:layout_marginTop="5dp"
android:nestedScrollingEnabled="true"
/>
this is my view pages
<androidx.viewpager.widget.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/tab_layout"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:nestedScrollingEnabled="true"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
Upvotes: 0
Views: 114
Reputation: 3693
Should be solved by setFillViewport (true)
:
<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:layout_width="match_parent"
android:id="@+id/nest_scrollview"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="mio.kon.yyb.nestedscrollviewbug.ScrollingActivity"
tools:showIn="@layout/activity_scrolling">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
And in your activity
set:
NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.nest_scrollview);
scrollView.setFillViewport (true);
Upvotes: 1