android布局Relative和gridLayout-android学习之旅(十六)
Relative布局简介
相对布局的组件是由兄弟组件和父组价决定的,因此这种布局被称为相对布局。
属性设置介绍
RelativeLayout.Layoutparam中只能设置为true和false的属性是:
需要依赖其他组件Id设置的属性:
除此之外,RelativeLayout还可以使用viewGroup.MarginLayoutparams的属性。
梅花布局的实例
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
android:id="@+id/view01"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
android:layout_below="@id/view01"
android:layout_alignLeft="@id/view01"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
android:layout_above="@id/view01"
android:layout_alignLeft="@id/view01"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
android:layout_toLeftOf="@id/view01"
android:layout_alignTop="@id/view01"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
android:layout_toRightOf="@id/view01"
android:layout_alignTop="@id/view01"/>
</RelativeLayout>
</LinearLayout>
表格布局
GridLayout是4.0以后才加入的布局,把这个空间分成rows*columns个格子,一个组件可以设置横跨多少列和多少行。
gridLayout的属性
常用属性:
GridLayout.Layoutparam的属性:
计算器界面的实例
package peng.liu.testview;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.widget.Button;
import android.widget.GridLayout;
import android.widget.TextView;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends Activity {
GridLayout grid = null;
String[] chars = new String[]{
"7","8","9","/",
"4","5","6","*",
"1","2","3","-",
".","0","+","+"
};
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
grid = (GridLayout) findViewById(R.id.root);
for (int i=0;i<chars.length;i++){
Button button = new Button(this);
button.setText(chars[i]);
button.setTextSize(40);
GridLayout.Spec rowSpec = GridLayout.spec(i / 4 + 2);
GridLayout.Spec columnSpec = GridLayout.spec(i%4);
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpec,columnSpec);
params.setGravity(Gravity.FILL);
grid.addView(button,params);
}
}
}
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical">
<GridLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/root"
android:rowCount="6"
android:columnCount="4">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_columnSpan="4"
android:layout_marginLeft="4px"
android:layout_marginRight="4px"
android:padding="5px"
android:textSize="50sp"
android:layout_gravity="right"
android:background="#eee"
android:textColor="#000"
android:text="0"
/>
</GridLayout>
</LinearLayout>
效果图
绝对布局
因为绝对布局,需要亲自设置组件的x位置,和y位置,所以一定程度上已经过时了。
属性
android:layout_x:设置组件的z坐标
android:layout_y:设置组件的Y坐标
可以这么说相对布局已经过时了~
距离单位介绍
android布局Relative和gridLayout-android学习之旅(十六)的更多相关文章
- Nodejs学习笔记(十六)--- Pomelo介绍&入门
目录 前言&介绍 安装Pomelo 创建项目并启动 创建项目 项目结构说明 启动 测试连接 聊天服务器 新建gate和chat服务器 配置master.json 配置servers.json ...
- Nodejs学习笔记(十六)—Pomelo介绍&入门
前言&介绍 Pomelo:一个快速.可扩展.Node.js分布式游戏服务器框架 从三四年前接触Node.js开始就接触到了Pomelo,从Pomelo最初的版本到现在,总的来说网易出品还算不错 ...
- 我的MYSQL学习心得(十六) 优化
我的MYSQL学习心得(十六) 优化 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...
- python3.4学习笔记(二十六) Python 输出json到文件,让json.dumps输出中文 实例代码
python3.4学习笔记(二十六) Python 输出json到文件,让json.dumps输出中文 实例代码 python的json.dumps方法默认会输出成这种格式"\u535a\u ...
- 深度学习(二十六)Network In Network学习笔记
深度学习(二十六)Network In Network学习笔记 Network In Network学习笔记 原文地址:http://blog.csdn.net/hjimce/article/deta ...
- 风炫安全web安全学习第三十六节课-15种上传漏洞讲解(一)
风炫安全web安全学习第三十六节课 15种上传漏洞讲解(一) 文件上传漏洞 0x01 漏洞描述和原理 文件上传漏洞可以说是日常渗透测试用得最多的一个漏洞,因为用它获得服务器权限最快最直接.但是想真正把 ...
- Android学习笔记(十六)——数据库操作(上)
//此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! Android 为了让我们能够更加方便地管理数据库,专门提供了一个 SQLiteOpenHelper帮助类, ...
- Android的ViewAnimator及其子类ViewSwitcher-android学习之旅(三十三)
ViewAnimator继承了FrameLayout,多个组件重合在一起,可以加入多个组件,然后切换的时候会有动画. ViewAnimator及其子类的继承关系 ViewAnimator常用属性 Vi ...
- 开发了5年android,我开始了go学习之旅
前言 做了近5年的android开发,最近项目也是不怎么忙,空闲的时候总会思考一些事情,不过作为移动开发,我个人觉得很有必要学习后台开发,由于公司是Go语言开发的,了解go语言一段时间后,我发现go语 ...
随机推荐
- 2015 多校联赛 ——HDU5334(构造)
Virtual Participation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- [USACO 5.1.3]乐曲主题
Description 我们用N(1 <= N <=5000)个音符的序列来表示一首乐曲,每个音符都是1..88范围内的整数,每个数表示钢琴上的一个键.很不幸这种表示旋律的方法忽略了音符的 ...
- 【SYZOI Round1】滑稽的树
Description zzsyz实验楼里面种了一棵滑稽树,只有滑稽之力达到大乘期的oier才能看到.虽然我们看不到,但是还是知道一些信息: 这真的是一棵树,由n个节点,n-1条边联通.一号滑稽果同时 ...
- [2017/5/28]FJ四校联考
来自FallDream的博客,未经允许,请勿转载,谢谢. 话说这一段时间算是过去了,好久好久之后终于又有联考了 没想到这次到我们学校出题,昨天才想起来,临时花一天赶了一套,我出了一个sbFFT,质量 ...
- [bzoj3668][Noi2014]起床困难综合症/[洛谷3613]睡觉困难综合症
来自FallDream的博客,未经允许,请勿转载,谢谢. 21 世纪,许多人得了一种奇怪的病:起床困难综合症,其临床表现为:起床难,起床后精神不佳.作为一名青春阳光好少年,atm 一直坚持与起床困难综 ...
- 作为开发也要了解的 mysql 优化思路
作为开发人员,数据库知识掌握的可能不是很深入,但是一些基本的技能还是要有时间学习一下的.作为一个数据库菜鸟,厚着脸皮来总结一下 mysql 的基本的不能再基本的优化方法. 为了更好的说明,我假想出来了 ...
- Python中模块json与pickle的功能介绍
json & pickle & shelve 1. json的序列化与反序列化 json的使用需要导入该模块,一般使用import json即可. json的序列化 方法1:json. ...
- SQL语句删除字段,改变字段长度
1.改变字段长度 ALTER TABLE T_MSG_SEND_R_ACC MODIFY reply_content VARCHAR(512); 2.删除字段ALTER TABLE MSG_TX_BA ...
- left join 连表时,on后多条件无效问题
http://www.cnblogs.com/guixiaoming/p/6516261.html left join 连表时,on后多条件无效问题 最近开发素材库项目,各种关系复杂的表,一度6张表的 ...
- 线性回归(Linear Regression)均方误差损失函数最小化时关于参数theta的解析解的推导(手写)
第一页纸定义了损失函数的样子, theta, X 和 y 的 shape, 以及最终的损失函数向量表现形式. 第二页纸抄上了几个要用到的矩阵求导公式,以及推导过程和结果. 要说明的是:推导结果与the ...