Android LinearLayout属性
2016-09-25 03:31
204 查看
LinearLayout 线性布局:既然是线性的,就有方向的问题。所以就得定义是分水平还是垂直
android:orientation="vertical" 定义为水平方向
android:orientation="horizontal" 定义为垂直方向
当然,你要是不定义的话,默认是垂直的。但是这种习惯不好。。。
还有什么常用的属性呢,,,
android:layou_weight="值" 分配权重 。使用这个属性时,该控件不需要去定义高度(即:android:layout_height="wrap_content")。这个值表示该控件对没有占用的空间的大小。
就比如:
你能很清楚的看到整个手机屏幕被TextView和Button各自占一半的空间。如果你把Button的layout_weight改成2,那就意味着整个LinearLayout的布局要分成3份,其中这个Button要占用2份的空间大小。总之,你要想把一块空间分割成几个小块,那你就可以使用这个属性了。
暂时就先这样吧。。。。。
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份的空间大小。总之,你要想把一块空间分割成几个小块,那你就可以使用这个属性了。
暂时就先这样吧。。。。。
相关文章推荐
- Android LinearLayout的android:layout_weight属性
- Android 之LinearLayout的属性
- LinearLayout属性android:orientation
- Android LinearLayout布局的layout_weight属性探究
- Android布局之LinearLayout与RelativeLayout的属性
- android(LinearLayout)属性详解
- 安卓学习笔记(LinearLayout属性android:orientation)
- Android 布局LinearLayout——属性baselineAligned的作用及baseline
- android随笔之linearLayout xml属性
- 对android LinearLayout中layout_weight属性使用
- Android LinearLayout的android:layout_weight属性
- 巧用android:divider属性设置LinearLayout中元素之间的间隔
- Android UI: LinearLayout中layout_weight 属性的使用规则
- Android LinearLayout 的几个属性
- 关于Android UI组件LinearLayout属性layout_weight与layout_width/height的问题
- 【android】巧用android:divider属性设置LinearLayout中元素之间的间隔
- android之LinearLayout中android:layout_weight属性理解
- LinearLayout android:divider属性
- Android界面——LinearLayout和RelativeLayout 属性对比
- android linearlayout 的gravity属性