'Zoom photo inside viewpager2

I tried to use PhotoِDarweeView inside ViewPager2. When I want to zoom in on the photo horizontally, it does not zoom in and instead the ViewPager2 swipes.

activity_media_view:

 <?xml version="1.0" encoding="utf-8"?>
 <androidx.constraintlayout.widget.ConstraintLayout 
 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:id="@+id/root"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@color/black"
 tools:context=".ui.MediaTopicActivity">

 <androidx.viewpager2.widget.ViewPager2
    android:id="@+id/viewPager"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    app:layout_constraintBottom_toTopOf="@+id/title"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/header"
    tools:background="@drawable/one"
    tools:layout_height="300dp" />

    <!-- other views -->

</androidx.constraintlayout.widget.ConstraintLayout>

fragment_photo:

<?xml version="1.0" encoding="utf-8"?>
<me.relex.photodraweeview.PhotoDraweeView 
xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


Solution 1:[1]

I resolved this by enabling nestedScrolling for my viewPager2

<androidx.viewpager2.widget.ViewPager2
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:nestedScrollingEnabled="true" />

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chiheb Mahdhi