Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anchor View in Android

I saw a reference about Anchor View in Android. If possible please provide an example with the explanation. I think it's related to some view group.

like image 389
Avijit Karmakar Avatar asked Sep 05 '25 16:09

Avijit Karmakar


2 Answers

Anchor View can be easily understood with the help of example below

<ImageView
        android:id="@+id/value_animator_subjectb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="?android:attr/textSelectHandle"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="190dp"
        android:layout_alignLeft="@+id/xyz_button" />

the ImageView is going to align its left edge with the left edge of view with id xyz_button so, in this case, view with id xyz_button is anchor view.

like image 61
Aamir Khan Avatar answered Sep 08 '25 05:09

Aamir Khan


In relative layout or in any view group, if we use so many attributes to position our view like:

android:layout_alignTop, android:layout_alignBottom etc.

In those attributes, we provide a view's id to align our view. Like:

android:layout_alignBottom="@+id/add_btn"

So, this given view is called as Anchor View. Here view with id addBtnView is our Anchor View.

like image 40
Avijit Karmakar Avatar answered Sep 08 '25 07:09

Avijit Karmakar