【发布时间】:2018-06-06 04:59:02
【问题描述】:
我有一个父 RelativeLayout 和 3 个子视图。视图一和视图二是对齐父底部。如果视图一可见,我希望我的视图三在视图一上方对齐,否则如果视图一不可见,则在视图二上方对齐。
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<View
android:id="@+id/one"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:background="@color/green"
tools:visibility="visible"/>
<View
android:id="@+id/two"
android:layout_width="250dp"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="@color/red"/>
<View
android:id="@+id/three"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_above="@id/one"
android:layout_marginBottom="10dp"
android:background="@color/yellow"/>
</RelativeLayout>
我知道如果我将视图 1 和视图 2 放入另一层并将视图 3 对齐在另一层之上它将起作用,但就当前架构而言,我不允许这样做。有没有其他方法可以实现这一目标? ConstraintLayout 能解决这个问题吗?
【问题讨论】:
标签: android android-layout android-constraintlayout android-relativelayout