2016-04-25Andriod基础 三种布局
2016-04-25 23:33
274 查看
线性布局
相对布局
帧布局
<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" tools:context="com.example.linearlayout.MainActivity" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#ff0000" android:orientation="horizontal"> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#ff0000"/> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#123456"/> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:background="#789876"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#00ff00" android:orientation="vertical"> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#ff0000"/> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="2" android:background="#123456"/> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="2" android:background="#789876"/> </LinearLayout> </LinearLayout>
相对布局
<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"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="左上"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="右上" android:layout_alignParentRight="true"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="左下" android:layout_alignParentBottom="true"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="右下" android:layout_alignParentBottom="true" android:layout_alignParentRight="true"/> <Button android:id="@+id/bt_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="居中" android:layout_centerInParent="true"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="居左" android:layout_alignTop="@id/bt_center" android:layout_toLeftOf="@id/bt_center"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="居右" android:layout_alignTop="@id/bt_center" android:layout_toRightOf="@id/bt_center"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="居上" android:layout_alignLeft="@id/bt_center" android:layout_above="@id/bt_center"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="居下" android:layout_alignLeft="@id/bt_center" android:layout_below="@id/bt_center"/> </RelativeLayout>
帧布局
<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"> <View android:layout_gravity="center" android:layout_width="200dp" android:layout_height="200dp" android:background="#ff0000" /> <View android:layout_gravity="center" android:layout_width="150dp" android:layout_height="150dp" android:background="#ffff00" /> <View android:layout_gravity="center" android:layout_width="100dp" android:layout_height="100dp" android:background="#ffffff" /> <View android:layout_gravity="center" android:layout_width="50dp" android:layout_height="50dp" android:background="#00ff00" /> </FrameLayout>
相关文章推荐
- uva753
- Shell 脚本知识回顾 (二) —— Shell变量
- 一看就懂系列之 feed的php具体实现细节
- ThinkPHP关联查询
- 深入理解HTTP协议
- 用jQuery来做简单的菜单栏的收缩
- hdu 5119 Happy Matt Friends(穷举子集类dp)
- [php-src]窥探Php内核中的变量
- 【Java】JDK类 CountDownLatch
- C++编译器隐含规则
- 用rem单位做网页时 文字内容超出溢出用点点点(…)省略号或者直接省略该怎么写
- Binary GCD algorithm
- ACM中Java的应用
- Leetcode #55. Jump Game 跳跃游戏 解题报告
- ACM中Java的应用
- 个人工作总结06
- 信源编码与信道编码
- java中获取资源文件
- uva10048
- c++作业4