第3章软件也要拼脸的 3.3详解4种基本布局
来源:互联网 发布:新业汽修软件视频 编辑:程序博客网 时间:2024/05/18 00:01
详解4种基本布局
1.线性布局LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:id="@+id/input_message" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="3" android:hint="Type something"/> <Button android:id="@+id/send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Send"/> <!--<Button--> <!--android:id="@+id/button2"--> <!--android:layout_width="wrap_content"--> <!--android:layout_height="wrap_content"--> <!--android:layout_gravity="center_vertical"--> <!--android:text="Button 2"/>--> <!--<Button--> <!--android:id="@+id/button3"--> <!--android:layout_width="wrap_content"--> <!--android:layout_height="wrap_content"--> <!--android:layout_gravity="bottom"--> <!--android:text="Button 3"/>--></LinearLayout>
2.相对布局RelativeLayout
相对于父布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="Button 1"/> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="Button 2"/> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Button 3"/> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:text="Button 4"/> <Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:text="Button 5"/></RelativeLayout>
相对于控件定位
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Button 3"/> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/button3" android:layout_toLeftOf="@id/button3" android:text="Button 1"/> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/button3" android:layout_toRightOf="@id/button3" android:text="Button 2"/> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button3" android:layout_toLeftOf="@id/button3" android:text="Button 4"/> <Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button3" android:layout_toRightOf="@id/button3" android:text="Button 5"/></RelativeLayout>
祯布局FrameLayout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" android:text="This is TextView"/> <ImageView android:id="@+id/image_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:src="@mipmap/ic_launcher"/></FrameLayout>
百分比布局
<android.support.percent.PercentFrameLayout xmlns:android ="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/button1" android:text="Button 1" android:layout_gravity="left|top" app:layout_widthPercent="50%" app:layout_heightPercent="50%" /> <Button android:id="@+id/button2" android:text="Button 2" android:layout_gravity="right|top" app:layout_widthPercent="50%" app:layout_heightPercent="50%" /> <Button android:id="@+id/button3" android:text="Button 3" android:layout_gravity="left|bottom" app:layout_widthPercent="50%" app:layout_heightPercent="50%" /> <Button android:id="@+id/button4" android:text="Button 4" android:layout_gravity="right|bottom" app:layout_widthPercent="50%" app:layout_heightPercent="50%" /></android.support.percent.PercentFrameLayout>
阅读全文
0 0
- 第3章软件也要拼脸的 3.3详解4种基本布局
- 第3章软件也要拼脸的 3.4.1引入布局
- 第一行代码3.3-详解四种基本布局
- 第一行代码之详解四种基本布局
- 3.3详解四种基本布局
- 详解四种基本布局
- 详解四种基本布局
- 金典 DIV+CSS 3行2列 布局详解--企业网站通用的基本布局详解
- 详解Android四种基本布局
- 第3章 布局
- 第3章 面板与布局-3.3 ST2.0的常用布局
- Nginx slab的实现 --- 第一篇“基本布局”
- 第4章 驱动程序的基本结构
- 第4章 基本的Git概念
- 第 4 章 数据库的基本操作
- 第3章 数据库的基本操作
- Android六大基本布局详解
- Android UI之五种基本布局详解
- MySQL INSERT ON DUPLICATE KEY UPDATE
- 把一个整数转换成8进制输出
- 抽象类VS接口
- 机器学习笔记——Scikit-learn库中的数据预处理:独热编码(二)
- 更改win10默认字体
- 第3章软件也要拼脸的 3.3详解4种基本布局
- 2017百度之星初赛(A)1001,1005,1006解题报告
- 8.14 lcs 2691
- 8.14 总结
- 【XSY1544】fixed 数学 强连通图计数
- 王学岗ToolBar,DrawLayout+Navigation的使用(三)
- 2017/8/14
- 分布式-微服务-集群的区别
- 观察者模式与事件监听机制