0

工作,我想創造這樣的dialogFragment:準則不DialogFragment

enter image description here

其實我得到這個我的手機上:

enter image description here

Button1是BUTTON2覆蓋。它看起來像guideline不起作用。 如果textView足夠長,它運作良好。但是如果textView很短,問題就會發生。我該如何解決這個問題。

我的對話框XML是:

<android.support.constraint.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" 
     android:padding="32dp"> 

     <TextView 
      android:id="@+id/dialog_message" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Dialog Message" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="parent" /> 

     <android.support.constraint.Guideline 
      android:id="@+id/guideline" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      app:layout_constraintGuide_percent="0.5" /> 

     <Button 
      android:id="@+id/dialog_button_positive" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="32dp" 
      android:layout_marginRight="32dp" 
      android:layout_marginTop="16dp" 
      android:gravity="center" 
      android:text="Positive" 
      android:textAppearance="?android:textAppearanceButton" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toLeftOf="@id/guideline" 
      app:layout_constraintTop_toBottomOf="@id/dialog_message" /> 

     <Button 
      android:id="@+id/dialog_button_negative" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="32dp" 
      android:layout_marginRight="32dp" 
      android:layout_marginTop="16dp" 
      android:gravity="center" 
      android:text="Negative" 
      android:textAppearance="?android:textAppearanceButton" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintLeft_toRightOf="@id/guideline" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toBottomOf="@id/dialog_message" /> 

    </android.support.constraint.ConstraintLayout> 

回答

0

你不需要的指引,您可以使用Chains代替。 試試這個

<android.support.constraint.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" 
    android:padding="32dp"> 

    <TextView 
     android:id="@+id/dialog_message" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Dialog Message" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <Button 
     android:id="@+id/dialog_button_positive" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="16dp" 
     android:layout_marginEnd="16dp" 
     android:gravity="center" 
     android:text="Positive" 
     app:layout_constraintHorizontal_chainStyle="packed" 
     android:textAppearance="?android:textAppearanceButton" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@id/dialog_button_negative" 
     app:layout_constraintTop_toBottomOf="@id/dialog_message" /> 

    <Button 
     android:id="@+id/dialog_button_negative" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="16dp" 
     android:layout_marginStart="16dp" 
     android:gravity="center" 
     android:text="Negative" 
     android:textAppearance="?android:textAppearanceButton" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toRightOf="@id/dialog_button_positive" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@id/dialog_message" /> 

</android.support.constraint.ConstraintLayout> 

如果你不熟悉鏈,這裏是一個small tutorial

+0

我照你的答案,但第二個按鈕顯示incomplete.I通過調用setLayout的解決這個問題。所以我在'onStart()'方法中添加'getDialog()。getWindow()。setLayout()'' –