LinearLayout 线性布局:既然是线性的,就有方向的问题。所以就得定义是分水平还是垂直
android:orientation="vertical" 定义为水平方向
android:orientation="horizontal" 定义为垂直方向
当然,你要是不定义的话,默认是垂直的。但是这种习惯不好。。。
还有什么常用的属性呢,,,
android:layou_weight="值" 分配权重 。使用这个属性时,该控件不需要去定义高度(即:android:layout_height="wrap_content")。这个值表示该控件对没有占用的空间的大小。
就比如:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:layout_width="match_parent"
android:layout_weight="1"
android:text="@string/hello_world" />
<Button
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="@string/hello_world"/>
</LinearLayout>
你能很清楚的看到整个手机屏幕被TextView和Button各自占一半的空间。如果你把Button的layout_weight改成2,那就意味着整个LinearLayout的布局要分成3份,其中这个Button要占用2份的空间大小。总之,你要想把一块空间分割成几个小块,那你就可以使用这个属性了。
暂时就先这样吧。。。。。