我有一个由按钮提示的弹出对话框。我最近又添加了几个要在屏幕上显示的类别,现在对话框的行为很奇怪。单击提示后,弹出对话框,但它并没有保持不变;相反,它反复变薄然后变宽,并且只是快速来回移动。有人遇到过这种情况么?以下是弹出窗口的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/productName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:text="TEST"
android:gravity="center"
android:textSize="25sp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/productImage" />
<TextView
android:id="@+id/category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Category"
android:textSize="20sp"
android:gravity="center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/productName" />
<TextView
android:id="@+id/size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="size"
app:layout_constraintRight_toLeftOf="@+id/powerType"
android:layout_marginRight="8dp"
app:layout_constraintTop_toTopOf="@+id/powerType"
android:layout_marginTop="0dp" />
<TextView
android:id="@+id/horsepower"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="horsepower"
android:gravity="left"
app:layout_constraintLeft_toRightOf="@+id/voltage"
android:layout_marginLeft="8dp"
app:layout_constraintTop_toTopOf="@+id/voltage"
android:layout_marginTop="0dp" />
<TextView
android:id="@+id/powerType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="power type"
android:gravity="left"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/category"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/category"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="@+id/category"
app:layout_constraintHorizontal_bias="0.473" />
<TextView
android:id="@+id/expProof"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="exp Proof"
android:gravity="left"
app:layout_constraintLeft_toRightOf="@+id/powerType"
android:layout_marginLeft="8dp"
app:layout_constraintTop_toTopOf="@+id/powerType"
android:layout_marginTop="0dp" />
<TextView
android:id="@+id/psi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PSI"
android:gravity="left"
app:layout_constraintRight_toLeftOf="@+id/gpm"
android:layout_marginRight="8dp"
android:layout_marginTop="0dp"
app:layout_constraintTop_toTopOf="@+id/gpm" />
<TextView
android:id="@+id/gpm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GPM"
android:gravity="left"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@+id/voltage"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/voltage"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="@+id/voltage"
app:layout_constraintHorizontal_bias="0.0" />
<TextView
android:id="@+id/rpm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RPM"
android:gravity="left"
app:layout_constraintLeft_toRightOf="@+id/gpm"
android:layout_marginLeft="8dp"
app:layout_constraintTop_toTopOf="@+id/gpm"
android:layout_marginTop="0dp" />
<TextView
android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textSize="20sp"
android:gravity="center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@+id/gpm" />
<Button
android:id="@+id/closeDetails"
android:layout_width="@dimen/popUpDetailSections"
android:layout_height="41dp"
android:text="@string/okayButton"
android:gravity="left"
android:textSize="15sp"
android:backgroundTint="@color/colorPrimary"
android:textColor="@color/white"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="32dp"
app:layout_constraintTop_toBottomOf="@+id/price" />
<ImageView
android:id="@+id/productImage"
android:layout_width="200dp"
android:layout_height="124dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="@drawable/exp_proof_pump_skid"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp" />
<TextView
android:id="@+id/voltage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="voltage"
android:gravity="left"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/powerType"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/powerType"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="@+id/powerType"
app:layout_constraintHorizontal_bias="0.0" />
<TextView
android:id="@+id/phase"
android:layout_width="wrap_content"
android:layout_height="16dp"
android:text="phase"
android:gravity="left"
app:layout_constraintRight_toLeftOf="@+id/voltage"
android:layout_marginRight="8dp"
app:layout_constraintTop_toTopOf="@+id/voltage"
android:layout_marginTop="0dp" />
</android.support.constraint.ConstraintLayout>
/image/3scVl.png <- 这是对话框的屏幕截图。所以边界不断扩大和压缩,文本也在不断移动。
最佳答案
试试这个
Window window = customDialog.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.WRAP_CONTENT);
关于java - Android Dialog 一直坐立不安 - 不会保持一种尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44544405/