java - Android Dialog 一直坐立不安 - 不会保持一种尺寸

标签 java android xml

我有一个由按钮提示的弹出对话框。我最近又添加了几个要在屏幕上显示的类别,现在对话框的行为很奇怪。单击提示后,弹出对话框,但它并没有保持不变;相反,它反复变薄然后变宽,并且只是快速来回移动。有人遇到过这种情况么?以下是弹出窗口的 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/

相关文章:

JAVA VM 内存选项 32bit 小于 2g 不工作

android - 我如何在android中制作下一页按钮(点击进入下一个 fragment )

Android从另一个复选框更改复选框首选项的值

php - 第 1 行第 3 列错误 : xmlParsePI : no target name

java - 使用注释插件 + JAXB 在 java 'field' 中插入自定义注释(基于 xsd -> java)

java - 无论内部长度不确定,如何将字符串拆分为有效的子字符串

java - 如何给定类名 "valueOf"枚举?

jquery - 使用 Javascript 或 JQuery 按元素值检索 XML 节点

java - 获取存储库中的所有文件夹和文档 Alfresco Restful

java - Android 抽屉打开只能工作一次