简单的LinearLayout线性布局
来源:互联网 发布:iphone刷机用什么软件 编辑:程序博客网 时间:2024/05/21 12:49
1. LinearLayout线性布局类似Swing中的流式布局
android:orientation="vertical" :指定排列方式值:vertical(垂直)horizontal(水平)android:gravity="":控制所有子控件在父容器中的位置
android:layout_width="" 布局宽度 wrap_content(只适应大小,强制性的使视图扩展以显示其全部内容)
android:layout_height="" 布局高度 match_parent (填充布局单元)
android:layout_weight="1" > 布局权重
android:layout_gravity="bottom" 布局重心 bottom(下端),right (右边), bottom|right(右下角)
2.如图,如何实现该功能
3. 思路:
左边按钮组:创建一个LinearLayout(为方便理解,用Lin1代替),将右上角按钮放入Lin1, 设置按钮的位置, 再创建一个LinearLayout(用Lin2代替),将右下角按钮放入Lin2, 设置按钮的位置,再将Lin1和Lin2 放入一个LinearLayout(用Lina代替)
中间按钮:创建一个LinearLayout(用Linb代替),将中间按钮放入Lin3, 设为居中
右边的按钮组:创建一个LinearLayout(为方便理解,用Lin4代替),将左上角按钮放入Lin4, 设置按钮的位置, 再创建一个LinearLayout(用Lin5代替),将左下角按钮放入Lin5, 设置按钮的位置,再将Lin4和Lin5 放入一个LinearLayout(用Linc代替)
最后将Lina,Linb,Linc放入最外面那个LinearLayout 即可,我是用垂直做的,你也可以试试用水平的方法
4. 源代码解析:
<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="horizontal"
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:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:text="左上按钮" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="左下按钮" />
</LinearLayout>
</LinearLayout>
<!-- 中间的按钮 -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="中间按钮" />
</LinearLayout>
<!-- 右边的按钮 -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:text="右上按钮" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:text="右下按钮" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
- 简单的LinearLayout线性布局
- 线性布局(LinearLayout)的简单使用
- 线性布局LinearLayout的使用
- Android的布局控件----LinearLayout(线性布局)
- LinearLayout (线性布局)的分析
- 自定义自动换行的线性布局linearLayout
- 线性布局LinearLayout的那些事儿
- LinearLayout(线性布局)中weight的难点
- 线性布局LinearLayout 的注意点
- LinearLayout简单的布局xml,
- Android 线性布局:LinearLayout
- LinearLayout 线性布局管理器
- LinearLayout(线性布局)
- LinearLayout:线性布局基础
- 线性布局LinearLayout
- LinearLayout线性布局
- LinearLayout(线性布局)
- LinearLayout—线性布局
- Python类和对象
- Android官方MVP架构示例项目解析
- OSG学习:阴影代码示例
- 【USACO题库】3.1.1 Agri-Net最短网络
- jquery Ajax请求提交数组
- 简单的LinearLayout线性布局
- mq 和 Httpclient
- static{}静态块
- 占位
- tp5 引入自定义类
- 【安全牛学习笔记】信息收集工具
- Java中使用Jedis操作Redis
- Windows打印体系结构之打印假脱机(Print Spooler)
- [JSOI2008]星球大战 洛谷P1197