安卓天天练练(二)相对布局和帧布局
2015-07-21 17:18
351 查看
相对布局很简单,就是利用与其他view的相对位置来布局,此例java文件完全不用写:
第二张图片在第一张右边,与第一张的顶端对齐。
第三章图片在第一张的下边,与第二章的右侧对齐。
是不是比css的相对布局更智能呢?这一例结束。
左上对齐的帧布局,也是个纯xml的例子:
没什么很特别的,仅仅是一层一层叠起来的不同大小的盒子,使用了FrameLayout标签。此例结束。
<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="com.narumi.absolutelayout.MainActivity" > <ImageView android:id="@+id/i01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/i1" /> <ImageView android:id="@+id/i02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/i2" android:layout_toRightOf="@id/i01" android:layout_alignTop="@id/i01" > </ImageView> <ImageView android:id="@+id/i03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/i3" android:layout_below="@id/i01" android:layout_alignRight="@id/i02" ></ImageView> </RelativeLayout>
第二张图片在第一张右边,与第一张的顶端对齐。
第三章图片在第一张的下边,与第二章的右侧对齐。
是不是比css的相对布局更智能呢?这一例结束。
左上对齐的帧布局,也是个纯xml的例子:
<FrameLayout 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="com.example.android_6_2.MainActivity" > <TextView android:id="@+id/tv01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/red" android:textSize="60px" android:text="@string/big" /> <TextView android:id="@+id/tv02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/blue" android:textSize="40px" android:text="@string/middle" /> <TextView android:id="@+id/tv03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/green" android:textSize="20px" android:text="@string/small" /> </FrameLayout>
没什么很特别的,仅仅是一层一层叠起来的不同大小的盒子,使用了FrameLayout标签。此例结束。
相关文章推荐
- Android-经常涉及到的权限
- socket编程<二>
- 二维码URL自动辨别Android和ISO设备,以便扫码后倒入不同的下载链接
- 快速排序
- 利用tween.js算法生成缓动效果
- PC-红警联机问题与下载
- 记失败的电话面试
- oracle 11g show spparameter 命令的使用
- Longest Valid Parentheses
- ./configure: error: the HTTP rewrite module requires the PCRE library
- input 之我见1
- 常见内存分配算法及优缺点
- Mysql启动自动设置max_connections为其他值
- Markdown 新手指南
- Intent的简介以及属性的详解
- Json解析工具Jackson(使用注解)
- VM创建的Mac虚拟机无法修改分辨率
- UNITY3D学习笔记3
- Android声明和使用权限
- netty 中MemoryAwareThreadPoolExecutor 简单分析