UI 布局
2016-04-16 14:30
351 查看
LinearLayout*** 线性布局
LinearLayout 线性布局这个布局会将它所包含的控件在线性方向上一次排列,默认排列方式是横向
可以通过代码来指定排列方式
android:orientation=”horizontal”
-android:orientation=”vertical”
需要注意的是,如果是横向排列,不能将控件的宽指定为match_parent
这样的话,这一个控件就会将整个水平方向占满。
同样的道理,如果是纵向排列,不能将空间的高指定为match_parent,这样一个控件会将整个纵向方向占满。
android:gravity属性,是用于指定文字在控件中的对齐方式。
android:layout_gravity是用于指定控件在布局中的对齐方式
android:layout_gravity="top" android:layout_gravity="center_vertical" android:layout_gravity="bottom"
需要注意的是,当布局为横向布局时,我们只能指定垂直方向的排列方向
当布局为纵向布局时,我们只能指定横向的排列方式。
比重 layout_weight
这个属性允许我们使用比例的方式来显示控件,在手机适配方面很有作用
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2"/> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"/> </LinearLayout>
你会发现,这里我们将两个控件的宽度都指定为0dp,这样只是一种规范的写法,因为此时的width已经不是由android:layout_width决定,而是由layout_weight决定,我们将TextView指定为2,Button指定为1,表示在水平方向,TextView占 2/3 个父布局的宽度, Button 占 1/3 个父布局的宽度
当然我们也可以这么弄,设置Button的大小为刚刚包裹住内容就好,剩下的空间就交给TextView吧。
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
相关文章推荐
- GUI - Web前端开发框架
- Android布局的小窍门?
- Web布局连载——两栏固定布局(五)
- 评价ui设计作品好坏的八个标准(界面/交互设计研究)
- 样式表CSS布局经验
- 在winform下实现左右布局多窗口界面的方法之续篇
- css网页布局中注意的几个问题小结
- DL.DT.DD实现左右的布局简单例子第1/2页
- 使用CSS框架布局的缺点和优点小结
- div+CSS网页布局的意义与副作用原因小结第1/2页
- 在winform下实现左右布局多窗口界面的方法
- 为Yahoo! UI Extensions Grid增加内置的可编辑器
- Android编程之代码创建布局实例分析
- Cocos2d-x UI开发之文本类使用实例
- CSS顶级技巧大放送,div+css布局必知
- 谈谈对jquery ui tabs 的理解
- 在IE 浏览器中使用 jquery的fadeIn() 效果 英文字符字体加粗
- 用div实现像table一样的布局方法
- UI Events 用户界面事件
- 精彩的Bootstrap案例分享 重点在注释!(选项卡、栅格布局)