ben*_*ben 1 java android android-constraintlayout
我如何View放在另一个Viewin后面ConstraintLayout?基本上我想实现这个:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
android:id="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
当视图 1 在 Z 轴上位于视图 2 后面时。
此代码将一个视图放在另一个视图下方。
使用约束将视图约束到底部和顶部。如果您希望视图占据整个空间,请使用 layout_height="0dp" 和 layout_constraintHeight_default="spread"。
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#F0F000"
android:orientation="horizontal"
app:layout_constraintHeight_default="spread"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintTop_toTopOf="parent"></LinearLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="#FF00FF"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"></LinearLayout>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5079 次 |
| 最近记录: |