Does anyone know if this screenshot
reflects this layout correctly?
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#FFFFFF80"
style="@android:style/TextAppearance.DeviceDefault.Large"
android:text="@string/text_1"/>
<TextView
android:id="@+id/text_view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
app:layout_anchor="@id/text_view1"
app:layout_anchorGravity="bottom|right"
android:background="#FFFF8080"
style="@android:style/TextAppearance.DeviceDefault.Large"
android:text="@string/text_2"/>
<TextView
android:id="@+id/text_view3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
app:layout_anchor="@id/text_view2"
app:layout_anchorGravity="bottom|right"
android:background="#FF8080FF"
style="@android:style/TextAppearance.DeviceDefault.Large"
android:text="@string/text_3"/>
</android.support.design.widget.CoordinatorLayout>
I was not expecting any overlap of text views, but may be my expectations are not correct?
app:layout_anchor: This attribute can be set on children of the CoordinatorLayout to attach them to another view. The value would be the id of an anchor view that this view should position relative to. Note that, the anchor view can be any child View (a child of a child of a child of a CoordinatorLayout, for example).
CoordinatorLayout is a super-powered FrameLayout . CoordinatorLayout is intended for two primary use cases: As a top-level application decor or chrome layout. As a container for a specific interaction with one or more child views.
As @ana 01 mention in comment, you should add android:layout_gravity="right"
in addition to app:layout_anchorGravity="right"
. By default app:layout_anchorGravity
works like if a dependent view aligns to an anchor's view by the center of the anchor's view.
So if you would like to align one view relatively to other, you should set an edge or gravity of a dependent view which will be used for alignment through out android:layout_gravity
attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With