LinearLayout代码中设置在某控件左侧
时间: 2024-02-25 14:53:48 浏览: 29
要将一个控件放在另一个控件的左侧,可以使用 `LinearLayout` 中的 `android:layout_toLeftOf` 属性。例如,如果你想将 `TextView1` 放在 `TextView2` 的左侧,可以使用以下代码:
```
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView2"/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView1"
android:layout_toLeftOf="@id/textView2"/>
</LinearLayout>
```
在这个例子中,`TextView1` 在 `TextView2` 的左侧,因为 `TextView1` 的 `android:layout_toLeftOf` 属性设置为 `@id/textView2`。`@id/textView2` 是 `TextView2` 的 ID,它告诉 `TextView1` 在 `TextView2` 的左侧放置。