Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layout_anchor equivalent for ConstraintLayout

How would I go about getting my fab to straddle two layouts in a ConstraintLayout like I could in a CoordinatorLayout?

XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                             xmlns:app="http://schemas.android.com/apk/res-auto"
                                             xmlns:tools="http://schemas.android.com/tools"
                                             android:layout_width="match_parent"
                                             android:layout_height="match_parent"
                                             android:background="#eeeeee"
                                             android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/myToolbar"
        android:layout_width="384dp"
        android:layout_height="56dp"
        android:background="@color/colorPrimary"
        android:elevation="0dp"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp"/>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/activity_horizontal_margin"
        app:layout_anchor="@+id/tvTest"
        app:layout_anchorGravity="end|bottom|right"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp"/>

    <CustomViews.FontText
        android:id="@+id/tvTest"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="50dp"
        android:text="TestText"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/myToolbar"/>
like image 900
Josh Laird Avatar asked Feb 07 '23 00:02

Josh Laird


1 Answers

For Example, You have two Layout ,

Layout 1 -> id="@+id/above_layout" , Layout 2 -> id="@+id/below_layout" ,

Then , And you want to set Fab Action Button in between Layout 1 and Layout 2,

app:layout_constraintRight_toRightOf="parent"

-> This will take view to right side

app:layout_constraintBottom_toBottomOf="@+id/above_layout", app:layout_constraintTop_toBottomOf="@+id/above_layout"

--> This two prop will achieve effect of app:layout_anchor="@+id/tvTest" ,app:layout_anchorGravity="end|bottom|right" , and id's of layout should be same.

 <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:scaleType="center"
        android:src="@drawable/ic_star"
        app:fabSize="mini"
        app:layout_constraintBottom_toBottomOf="@+id/above_layout"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/above_layout"/>

I hope this helps.

like image 141
zephyr Avatar answered Feb 08 '23 14:02

zephyr