我如何让我的工厂跨越ConstraintLayout
中的两个布局,就像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"/>
答案 0 :(得分:1)
例如,您有两个Layout,
布局1-> id =“ @ + id / above_layout” , 布局2-> id =“ @ + id / below_layout” ,
然后,您想要在布局1和布局2之间设置Fab Action Button。
app:layout_constraintRight_toRightOf =“父母”
-> 这将在右侧显示
app:layout_constraintBottom_toBottomOf =“ @ + id / above_layout”, app:layout_constraintTop_toBottomOf =“ @ + id / above_layout”
-> 这两个道具将达到app:layout_anchor =“ @ + id / tvTest”,app:layout_anchorGravity =“ end | bottom | right”的效果,并且布局的id应该相同。
<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"/>
我希望这会有所帮助。