2017-06-22 105 views
0

如何将View置于另一个ViewConstraintLayout?基本上我想实现这一点:在约束层布局中的另一个视图下放置视图

<?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" /> 

在厂景是在Z轴视图2。

回答

0

只是一味

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <TextView 
     android:id="@+id/view1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="VIEW 1"/> 

    <TextView 
     android:id="@+id/view2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="VIEW 2" 
     app:layout_constraintTop_toTopOf="@+id/view1" 
     app:layout_constraintStart_toStartOf="@+id/view1" 
     app:layout_constraintEnd_toEndOf="@+id/view1" 
     app:layout_constraintBottom_toBottomOf="@+id/view1"/> 
</android.support.constraint.ConstraintLayout> 

指挥一个ConstraintLayout你可以使用的app:layout_constraint...大量属性来实现您正在寻找最佳的布局儿童。

这些layout_constraint所有4这些都不是必要的,他们中的任何一个都可以做到这一点。但只是为了向你展示你的选择。

+1

添加'app:layout_constraintTop_toBottomOf =“@ + id/view1”'将在视图的顶部和底部之间创建约束,并且不会将它们放在彼此之上。这不是我试图实现的目标 – ben

+0

当你说他们把它们放在另一个上面时,你的意思是你想让view1垂直地位于视图2之上,还是字面上方,因为它们重叠? @ben –

+0

我看到,也许你希望它们互相重叠,我会相应地更新代码。 –

相关问题