Android textView 在LinearLayout正中间,在LinearLayout左边,LinearLayout右边
时间: 2024-01-06 18:13:52 浏览: 38
可以通过在 LinearLayout 中使用不同的布局参数来实现 Android TextView 在 LinearLayout 正中间、在 LinearLayout 左边或右边的效果。具体实现方法如下:
1. Android TextView 在 LinearLayout 正中间
将 TextView 的布局参数设置为 center,可以使 TextView 在 LinearLayout 中央。
```
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_gravity="center"/>
```
2. Android TextView 在 LinearLayout 左边
将 TextView 的布局参数设置为 left,可以使 TextView 在 LinearLayout 左边。
```
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_gravity="left"/>
```
3. Android TextView 在 LinearLayout 右边
将 TextView 的布局参数设置为 right,可以使 TextView 在 LinearLayout 右边。
```
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_gravity="right"/>
```