Position view below another view in CoordinatorLayout in android Position view below another view in CoordinatorLayout in android xml xml

Position view below another view in CoordinatorLayout in android


I assume you are trying to position views inside of the CollapsingToolbarLayout. The CollapsingToolbarLayout extends FrameLayout, so the only possibility is to position views is to utilize view margin and gravity. In your case you could position a ImageView like:

<ImageView    android:layout_width="match_parent"    android:layout_height="100dp"    android:layout_marginTop="140dp" <-height of the ScrollView/>

If you are trying to add the new ImageView directly to the CoordinatorLayout you can utilize a anchor:

<ImageView    android:layout_width="match_parent"    android:layout_height="100dp"    app:layout_anchor="@+id/post_text_layout" <-view to anchor the imageview    app:layout_anchorGravity="bottom" <- specifies edge of the anchor that should be used    android:layout_gravity="bottom" <- how to position this view relatively to the anchoring position/>