Android 根据内容高度的变化调整PopupWindow的大小

Android 根据内容高度的变化调整PopupWindow的大小,android,android-studio,android-layout,android-fragments,Android,Android Studio,Android Layout,Android Fragments,我有一个PopupWindow,其中包含一个ViewPager,每个片段中都有一个RecyclerView。 弹出窗口的布局: <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layou

我有一个PopupWindow,其中包含一个ViewPager,每个片段中都有一个RecyclerView。 弹出窗口的布局:

<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="wrap_content">

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="6mm"
        android:paddingTop="1mm"
        app:layout_constraintTop_toTopOf="parent"
        app:tabGravity="fill"
        app:tabIndicatorColor="@android:color/black"
        app:tabIndicatorGravity="bottom"
        app:tabIndicatorHeight="1dp"
        app:tabPaddingStart="0dp"
        app:tabSelectedTextColor="@android:color/black"
        app:tabTextAppearance="@style/AppTheme.TabLayout.Tab"
        app:tabTextColor="@color/colorTabSecondary" />

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tabs" />
</androidx.constraintlayout.widget.ConstraintLayout>

片段具有相同的布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBackground">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

当我在fragments recyclerview中放置新项目时,如何更改弹出窗口高度

更新:只需使用
PopupWindow.Update()