2017-02-13 19 views

Antwort

11

Hier ein visuelles Beispiel.

  1. Wählen Sie die Ansichten
  2. Rechts klicken und Kette wählen> Erstellen horizontalen Ketten

enter image description here

Siehe auch

+0

Dies funktioniert nicht, wenn die Schaltflächen unterschiedliche Breiten haben – gjsalot

-1

Verwenden Sie lineare Layout als übergeordnetes Layout und innerhalb lineares Layout (horizontal) verwenden Sie Schaltflächen und für jede Schaltfläche verwenden Sie Gewicht Eigenschaft = 1 wird es funktionieren.

+0

ich kenne die Lösung mit linearem Layout. Können Sie mir helfen, das Constraint-Layout zu verwenden? –

1

das Probieren Sie es für mich funktioniert ...

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

<Button 
    android:id="@+id/button_save" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:text="@string/button_save_text" 
    android:layout_marginStart="8dp" 
    android:layout_marginBottom="8dp" 
    android:layout_marginEnd="4dp" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintRight_toLeftOf="@+id/button_share" 
    app:layout_constraintHorizontal_chainStyle="spread" /> 

<Button 
    android:id="@+id/button_share" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:text="@string/button_share_text" 
    android:layout_marginStart="4dp" 
    android:layout_marginEnd="8dp" 
    android:layout_marginBottom="8dp" 
    app:layout_constraintLeft_toRightOf="@+id/button_save" 
    app:layout_constraintRight_toLeftOf="parent" 
    app:layout_constraintBottom_toBottomOf="parent" /> 

</android.support.constraint.ConstraintLayout> 
+0

Bitte beziehen Sie sich auf diesen Link, um mehr über diese http://StackOverflow.com/Questions/37518745/Evenly-Spacing-Views-Using-Constraintlayout –

+0

Dank es funktioniert –

1

Versuchen Sie den Code unten

<?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:id="@+id/activity_main_inference" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_editor_absoluteX="0dp" 
    app:layout_editor_absoluteY="80dp" 
    tools:layout_editor_absoluteX="0dp" 
    tools:layout_editor_absoluteY="80dp"> 


    <Button 
     android:text="Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/button7" 
     android:layout_marginTop="16dp" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="16dp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     tools:layout_constraintRight_creator="1" 
     tools:layout_constraintLeft_creator="1" /> 

    <Button 
     android:text="Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/button8" 
     app:layout_constraintTop_toTopOf="@+id/button7" 
     tools:layout_constraintLeft_creator="1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginStart="8dp" 
     app:layout_constraintRight_toLeftOf="@+id/button7" 
     android:layout_marginEnd="8dp" /> 

    <Button 
     android:text="Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/button9" 
     app:layout_constraintBaseline_toBaselineOf="@+id/button7" 
     tools:layout_constraintRight_creator="1" 
     android:layout_marginEnd="7dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginStart="8dp" 
     app:layout_constraintLeft_toRightOf="@+id/button7" /> 
</android.support.constraint.ConstraintLayout> 
+1

dieses ist die echte Antwort von der Frage. –

Verwandte Themen