Setzen Sie Elemente linear und am unteren Rand des Bildschirms in Android

Die beste Möglichkeit, Elemente in Android linear zu platzieren, ist die Verwendung von LinearLayout. Attribut angeben 'Orientierung'des LinearLayout zu'vertikal‘.

Nun sind beliebig viele Elemente in der linearen Anordnung vertikal angeordnet.

Um die Elemente am unteren Rand des Bildschirms auszurichten, verwenden Sie ConstraintLayout und fügen Sie dem LinearLayout Einschränkungen hinzu, um ihn am unteren Rand des Bildschirms anzuhängen.

Unten finden Sie den Beispielcode, in dem sich zwei TextView (s) befinden und der Container LinearLayout am unteren Rand des Bildschirms angebracht ist.

<? xml version = "1.0" coding = "utf-8"?> <android.support.constraint.ConstraintLayout xmlns: android = "https://schemas.android.com/apk/res/android" xmlns: app = "https://schemas.android.com/apk/res-auto" xmlns: tools = "https://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_parent": context = ". MainActivity"> <LinearLayout android: layout_width = "match_parent" android: layout_height = "wrap_content" android: orientation = "vertical" app: layout_constraintBottomOf = "parent" app: layout_constraintEnd_toEndOf = "übergeordneter" appart_auf_inhalt " "> <TextView android: id =" @ + id / element1 "android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: text =" Dies ist das Element 1 "/> <TextView android: id =" @ + id / element2 "android: layout_width =" match_parent "android: layout_height =" wrap_content "android: text =" Dies ist das Element 2 "/> </ LinearLayout> </android.support.constraintLayout>

Leave a Reply

Your email address will not be published. Required fields are marked *