安卓实现线性布局的相关代码
时间: 2023-10-26 15:18:12 浏览: 44
安卓实现线性布局可以使用LinearLayout控件,以下是一个示例代码:
```xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>
</LinearLayout>
```
这个布局中,我们使用了一个LinearLayout控件,设置了它的宽度为match_parent,高度为wrap_content,方向为horizontal(水平方向排列子控件),对齐方式为居中垂直。在LinearLayout中,我们添加了一个ImageView和一个TextView作为子控件,分别用于显示图像和文本内容。我们可以根据需要修改子控件的属性来实现不同的布局效果。