Ich habe eine ConstraintLayout
, die 3 Tasten horizontal enthält. Ich möchte, dass die 3 Tasten eine feste Breite haben und gleichmäßig über die Breite des Layouts verteilt sind.Android ConstraintLayout: Drei Tasten gleichmäßig über die Breite verteilen
Antwort
Hier ein visuelles Beispiel.
- Wählen Sie die Ansichten
- Rechts klicken und Kette wählen> Erstellen horizontalen Ketten
Siehe auch
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.
ich kenne die Lösung mit linearem Layout. Können Sie mir helfen, das Constraint-Layout zu verwenden? –
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>
Bitte beziehen Sie sich auf diesen Link, um mehr über diese http://StackOverflow.com/Questions/37518745/Evenly-Spacing-Views-Using-Constraintlayout –
Dank es funktioniert –
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>
dieses ist die echte Antwort von der Frage. –
- 1. verteilen Tasten in div gleichmäßig
- 2. Verteilen Sie Tasten so gleichmäßig wie möglich
- 3. Drei Tasten gleichmäßig aufgeteilt lineares Layout
- 4. android verteilen gleichmäßig imageview android programmatisch
- 5. Verteilen DIV Kinder gleichmäßig über die gesamte Höhe und Breite des Behälters
- 6. Gleichmäßig Textansichten über lineares Layout horizontal verteilen und Inhalt umhüllen
- 7. Android: ConstraintLayout Layout 4 Tasten in 2 Gruppen nicht gleichmäßig verteilt
- 8. Verteilen Sie Kisten mit verschiedenen Höhen gleichmäßig über Flexbox-Spalten
- 9. Wie gleichmäßig im Spark verteilen?
- 10. Elemente gleichmäßig in Spalten verteilen
- 11. Reagieren native flexbox: Verteilen Sie die Artikel gleichmäßig
- 12. Emacs Windows, verteilen Sie die Breite durch den Rahmen
- 13. Wie wird die Breite der Fenstereditor-Registerkarten festgelegt, um sie gleichmäßig zu verteilen?
- 14. Bildschirm gleichmäßig teilen android
- 15. Gleichmäßig verteilen Duft in einer kollaborativen Diffusionsmatrix
- 16. Verteilen Objekte gleichmäßig nach ihrem Attribut
- 17. Gleichmäßig Punkte auf einem Kreis verteilen
- 18. So verteilen Sie HTML-Listenelemente gleichmäßig in einer ungeordneten Liste
- 19. Constraintlayout Bug Android Studio
- 20. Platz über Elementen in ConstraintLayout
- 21. Android LinearLayout über ein anderes in ConstraintLayout
- 22. Verteilen Sie die Namen gleichmäßig auf Zeilen basierend auf Countif
- 23. WindowManager - Zeichnung über die Navigationsleiste (Tasten) Android
- 24. Werte der Liste 1 ungleiche Länge über die Liste 2 linear/gleichmäßig verteilen
- 25. Automatische Anordnung Problem für die Breite gleichmäßig in iOS iPhone
- 26. ConstraintLayout mit DataBinding falsche Breite in RecyclerView
- 27. Tasten sind nicht die gleiche Breite
- 28. Bootstrap 4 gleichmäßig Platz Tasten im Container
- 29. Funktion/Algorithmus, um Daten gleichmäßig zwischen Prozessen zu verteilen
- 30. Chart.js: verteilen Sie Ticks bei Verwendung von maxTicksLimit gleichmäßig
Dies funktioniert nicht, wenn die Schaltflächen unterschiedliche Breiten haben – gjsalot