android学习笔记(8)linearlayout与android:layout_weight学习
2015-08-09 12:34
531 查看
对应若水老师的第十课
一,linearlayout
线性布局,布局文件中设置多个linearlayout来达到整体线性布局的风格.
android:gravity="right"对齐方式,居右对齐,gravity是重心的意思
常用参数:center(居中),bottom(下),top(上),right(右),left(左)
二,android:layout_weight
给控件分配可权值,不分配默认为0
权值为0的控件按原来的方式给他布局;分配了权值的控件,在除去权值为0的控件之外的区域按权值布局,
例如:布局中有2个控件,一个android:layout_weight="2",另一个android:layout_weight="1"则整个屏幕内三分之二被第一个控件占据,剩下的三分之一被第二个控件占据.
例子:实现如图布局:
一,linearlayout
线性布局,布局文件中设置多个linearlayout来达到整体线性布局的风格.
android:gravity="right"对齐方式,居右对齐,gravity是重心的意思
常用参数:center(居中),bottom(下),top(上),right(右),left(左)
二,android:layout_weight
给控件分配可权值,不分配默认为0
权值为0的控件按原来的方式给他布局;分配了权值的控件,在除去权值为0的控件之外的区域按权值布局,
例如:布局中有2个控件,一个android:layout_weight="2",另一个android:layout_weight="1"则整个屏幕内三分之二被第一个控件占据,剩下的三分之一被第二个控件占据.
例子:实现如图布局:
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <LinearLayout android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 水平布局 --> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <EditText android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ff0000" android:layout_weight="1"> </EditText> <EditText android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="#00ff00" > </EditText> <EditText android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="#0000ff"> </EditText> </LinearLayout> <!-- 垂直布局 --> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:layout_gravity="right"> <EditText android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="#2F2F4F"> </EditText> <EditText android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="#B87333"> </EditText> </LinearLayout> </LinearLayout> </RelativeLayout>
相关文章推荐
- Android中自定义属性(attrs.xml,TypedArray的使用)
- Android 的消息机制
- 使用SpannableString设置部分文字大小、颜色、超链接、点击事件
- Android核心基础-8.Android四大组件之Activity-1.创建、启动
- RecyclerView之动画效果
- Android Handler的使用(2)
- Android之——常用手机号码功能
- Android AIDL线程通信之Service回调客户端Activity
- Android蓝牙开发
- android.graphics.drawable.Drawable注释翻译
- Android中实现多线程下载的两种方式示例及浅析之二(Thread加断点续传)
- MyEclips常见问题
- 自定义控件(PullToRefreshListView,XListView)的原理
- android学习笔记(6)Activity高级+android:theme学习
- Android-菜单库-ArcMenu、LineMenu、RoundMenu
- Android运行时ART简要介绍和学习计划
- SPICE协议在Android上的几个优化要点
- Android中怎样获取手机分辨率
- android自定义回调接口
- android简单可操作的屏幕适配