The end edge is anchored to the end edge of the ConstraintLayoutĪs a result, with a width of 0dp, the Button will be stretched to fill the space between those two anchor positions.The start edge is anchored to the end edge of the TextView.For a child of ConstraintLayout, though, 0dp means “the width is determined by the horizontal constraints”. Normally, this would mean a width of zero dp, which would be a bit short. The Button also has This says that we want to anchor the start edge of the Button to the end edge of the TextView (whose android:id value is Button has an unusual android:layout_width value: 0dp. The ties into the declared in the android:id attribute of the Button, so the ConstraintLayout knows what widget is the target of this anchoring rule. Here, we are anchoring the baseline of the TextView to the baseline of the Button, so wherever the Button winds up, the TextView will have a matching vertical position. A TextView - and any subclasses, like Button - has a baseline. The TextView also has Here, “baseline” refers to the invisible line that text appears to “sit” upon. app:layout_constraintEnd_toEndOf to anchor the “end” of the Button to the “end” of the ConstraintLayout, where “end” is on the right for left-to-right languages and on the left for right-to-left languages.app:layout_constraintTop_toTopOf="parent" to anchor the top of the Button to the top of the ConstraintLayout.So, app:layout_constraintStart_toStartOf="parent" will anchor the start edge of the TextView to the start side of the ConstraintLayout. The “something else” is the ConstraintLayout itself ( "parent").We are trying to anchor that edge to the start edge of something else ( toStartOf).We are trying to constrain the “start” edge of the widget ( constraintStart), where the “start” edge is on the left for left-to-right languages and on the right for right-to-left languages.app:layout_constraintStart_toStartOf="parent" says: All attributes starting with app:layout_constraint are rules for children of ConstraintLayout. The TextView has app:layout_constraintStart_toStartOf="parent". However, both also have anchoring rules, indicating where the widgets should be positioned within the ConstraintLayout. Both have IDs, sizes, and captions (via android:text). There are two XML elements that are contained in the ConstraintLayout: our TextView and our Button. We also give the ConstraintLayout padding on all four sides, so the contents of the ConstraintLayout will be inset from the edges by however much calls for ( 8dp in this case). In this case, the “parent” is a container that occupies most of the space on the screen, so the ConstraintLayout will fill that space. We give that ConstraintLayout a height and width of match_parent, which indicates that this widget or container should fill up the available space of its parent container. ConstraintRow/src/main/res/layout/activity_main.xml)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |