android,如何垂直居中对齐RelativeLayout的子项
有一个RelativeLayout,它有左、右两个子容器,右侧的高度可能较高/或较短,左侧容器有几个子项,其中一些子项可能动态可见或不可见 比如左侧有垂直AAA、bbb、CCC等。它们应该垂直分布可用空间。因此,当bbb被隐藏时,剩余的AAA、CCC将在上面和下面有更多的空间android,如何垂直居中对齐RelativeLayout的子项,android,android-studio,vertical-alignment,android-relativelayout,Android,Android Studio,Vertical Alignment,Android Relativelayout,有一个RelativeLayout,它有左、右两个子容器,右侧的高度可能较高/或较短,左侧容器有几个子项,其中一些子项可能动态可见或不可见 比如左侧有垂直AAA、bbb、CCC等。它们应该垂直分布可用空间。因此,当bbb被隐藏时,剩余的AAA、CCC将在上面和下面有更多的空间 ------------------- ------------------------ | AAA | | | | |
------------------- ------------------------
| AAA | | |
| | | |
| bbb | | Right side |
| | | |
| CCC | | |
------------------- ------------------------
bbb is visibility = "gone"
------------------- ------------------------
| | | |
| AAA | | |
| | | Right side |
| CCC | | |
| | | |
------------------- ------------------------
如果左侧短于右侧,则更改为垂直线性布局以包裹左侧,并在AAA以上和CCC以下添加垫片将起作用,但如果左侧高于右侧,则不起作用
当左侧内容较多且高度高于右侧时,应为:
------------------- ========================
| AAA | |----------------------|
| | | |
| ddd | | |
| bbb | | Right side |
| eee | |
| | | |
| CCC | |----------------------|
------------------- ========================
具有如下布局,但当左侧的一些子视图被隐藏时,它不会调整,如:
成功了,但希望有更好的方法
<RelativeLayout>
<!-- left side -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/right_side_container"
android:orientation="vertical">
<Space
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<!-- item AAA --->
<!-- item ddd --->
<!-- item bbb --->
<!-- item eee --->
<!-- item ccc --->
<Space
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<LinearLayout >
<!-- right side -->
<FrameLayout
android:id="@id/right_side_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
tools:visibility="visible"
>
<!-- children items -->
</FrameLayout>
</RelativeLayout>
<RelativeLayout>
<!-- left side -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/right_side_container"
android:orientation="vertical">
<Space
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<!-- item AAA --->
<!-- item ddd --->
<!-- item bbb --->
<!-- item eee --->
<!-- item ccc --->
<Space
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<LinearLayout >
<!-- right side -->
<FrameLayout
android:id="@id/right_side_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
tools:visibility="visible"
>
<!-- children items -->
</FrameLayout>
</RelativeLayout>