我将如何让我的工厂在 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"/>
最佳答案
例如,您有两个 Layout ,
布局 1 -> id="@+id/above_layout" ,
布局 2 -> id="@+id/below_layout" ,
然后,您想在布局 1 和布局 2 之间设置 Fab Action Button,
app:layout_constraintRight_toRightOf="parent"
-> 这将查看右侧
app:layout_constraintBottom_toBottomOf="@+id/above_layout", app:layout_constraintTop_toBottomOf="@+id/above_layout"
--> 这两个 Prop 会达到 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"/>
我希望这有帮助。
关于android - Layout_anchor 等效于 ConstraintLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39837703/