0

Je veux creat un dialogFragment comme ceci:GuideLine ne fonctionnent pas dans DialogFragment

enter image description here

En fait, je suis sur mon téléphone:

enter image description here

button1 est couvert par Bouton2 . Il semble que le guide ne fonctionne pas. Si textView est assez long, cela fonctionne bien. Mais si textView est court, le problème arrivera. Comment puis-je résoudre le problème?

ma boîte de dialogue XML est:

<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> 

Répondre

0

Vous n'avez pas besoin de la ligne directrice, vous pouvez utiliser Chains à la place. Essayez cette

<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> 

Si vous n'êtes pas familier avec les chaînes, voici une small tutorial

+0

Je l'ai fait en tant que votre réponse, mais le deuxième bouton affiché incomplete.I résoudre le problème par appel setLayout. Donc j'ajoute 'getDialog(). GetWindow(). SetLayout()' dans la méthode 'onStart()' –