布局
Android studio存在很多布局,如线性布局(LinearLayout),表格布局(TableLayout),相对布局(RelativeLayout)等。
这篇讲述的是其中的线性布局及一些常用的属性。
首先创建布局


- Layout File Name:文件名后面不用写".xml"。
- Root Tag :默认是线性布局,可以改成其他布局。
接下来编写XML文件
orientation属性
线性布局里的orientation是一个很重要的属性,表示控件的排列方向。该属性存在两个值,vertical(垂直)和horizontal(水平)。
例子1:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button android:id="@+id/button"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="B1" />
<Button android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="B2" />
</LinearLayout>
结果:

上面例子1中的两个按钮是垂直排列。
而如果将orientation的值改为horizontal(水平排列),则效果为:


本文详细介绍了Android中的线性布局(LinearLayout),包括orientation属性、layout_width、layout_height、layout_weight、layout_gravity和gravity的使用,并通过实例展示了它们的效果。同时提到了SimpleAdapter在适配器中的应用。
最低0.47元/天 解锁文章
7315

被折叠的 条评论
为什么被折叠?



