这有点简化,使问题更容易提出。Android布局相对于LinearLayout
我有一个垂直方向的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作为根布局,并将视图设置为竖直LinearLayout的Right。 –
这将对齐到线性布局的右侧,而不是包含的按钮。 – Mitch