Android studio ViewPager2不遵守布局约束

Android studio ViewPager2不遵守布局约束,android-studio,android-constraintlayout,android-viewpager2,Android Studio,Android Constraintlayout,Android Viewpager2,我希望有一个带有图像的活动,图像下面有一个viewpager2,它将根据用户的点击而改变。然后我提出了这个活动的布局: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schema

我希望有一个带有图像的活动,图像下面有一个viewpager2,它将根据用户的点击而改变。然后我提出了这个活动的布局:

<?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/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".HomeActivity" >

    <ImageView
        android:id="@+id/profile_pic_imageView"
        android:layout_width="220dp"
        android:layout_height="220dp"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/ic_logo"/>

    <androidx.viewpager2.widget.ViewPager2
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/profile_pic_imageView" />

</androidx.constraintlayout.widget.ConstraintLayout>

但是,它在imageview的顶部。。。我需要改变什么?我尝试了匹配父对象和0dp,但它始终位于图像视图的顶部

您需要给ViewPager底部约束,正如我们给顶部和底部约束一样,我们可以给高度0dp


 <?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/profile_pic_imageView"
        android:layout_width="220dp"
        android:layout_height="220dp"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/ic_launcher_background" />

    <androidx.viewpager2.widget.ViewPager2
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/profile_pic_imageView" />

</androidx.constraintlayout.widget.ConstraintLayout>