【发布时间】:2017-06-16 03:50:07
【问题描述】:
这有点简化,以使问题更容易提出。
我有一个垂直方向的 LinearLayout。我不允许修改 LinearLayout,但我想在 LinearLayout 中每个元素的右侧显示一个按钮。我尝试查看 ConstraintLayout 和 RelativeLayout,但我收到一条消息,因为它们不是兄弟姐妹,所以这不起作用。
当视图位于 LinearLayout 内时,如何在视图右侧显示按钮?
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--
DO NOT MODIFY THIS SECTION!!!
-->
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_constraintTop_toTopOf="parent"
android:layout_constraintBottom_toBottomOf="parent"
android:layout_constraintLeft_toLeftOf="parent" >
<Button
android:id="@+id/a"
android:text="A"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/b"
android:text="B"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/c"
android:text="C"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/d"
android:text="D"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<!--
END OF DO NOT MODIFY SECTION!!!
-->
<!--
PLACE THIS BUTTON TO THE RIGHT OF BUTTON C
-->
<Button
android:id="@+id/c_aux"
android:text="C AUX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_constraintLeft_toRightOf="@id/c" />
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
贴出你试过的代码。
-
以RelativeLayout为根布局,使view为toRightOf的Vertical LinearLayout。
-
这将与线性布局的右侧对齐,而不是包含的按钮。
标签: android android-layout android-linearlayout android-relativelayout android-constraintlayout