gridlaylout 简单布局
package com.example.gridlayout; import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.Button;
import android.widget.GridLayout; public class MainGrid extends Activity {
GridLayout grd;
String[] chas=new String[]
{
"","","","*"
,"","","","/"
,"","","","+"
,"",".","=","-" }; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_grid);
grd=(GridLayout)findViewById(R.id.root);
for(int i=;i<chas.length;i++)
{
Button bt=new Button(this);
bt.setText(chas[i]);
bt.setTextSize();
bt.setHeight();
GridLayout.Spec rowSpec = GridLayout.spec(i / + );
// 指定该组件所在列
GridLayout.Spec columnSpec = GridLayout.spec(i % );
GridLayout.LayoutParams params = new GridLayout.LayoutParams(
rowSpec , columnSpec);
// 指定该组件占满父容器
params.setGravity(Gravity.FILL);
grd.addView(bt , params); }
}
}
<?xml version="1.0" encoding="utf-8" ?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="6"
android:columnCount="4"
android:id="@+id/root"
>
<!-- 定义一个横跨4列的文本框,
并设置该文本框的前景色、背景色等属性 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_columnSpan="4"
android:textSize="50sp"
android:layout_marginLeft="4px"
android:layout_marginRight="4px"
android:padding="5px"
android:layout_gravity="right"
android:background="#eee"
android:textColor="#000"
android:text="0"/>
<!-- 定义一个横跨4列的按钮 -->
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_columnSpan="4"
android:text="清除"/>
</GridLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gridlayout"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="21" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainGrid"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </manifest>
gridlaylout 简单布局的更多相关文章
- WPF简单布局 浅尝辄止
WPF的窗口只能包含一个元素,为了在WPF窗口中放置多个元素并创建更实用的用户界面,需要在窗口上放置一个容器,然后在容器中放置其它元素. 注意:造成这一限制的原因是window类继承自 ...
- table 和 div 简单布局
table 简单布局 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// ...
- 【JQuery Easy UI】后台管理系统的简单布局分享
重要说明:本博已迁移到 石佳劼的博客.有疑问请到 文章新地址 留言..! 近期做的一个简单的后台管理系统,当中用到了JQuery Easy UI框架,对于撸主这样的把控件能摆整齐就谢天谢地的码农来说, ...
- Masonry 布局 cell 高度适应的一种方案(实现类似朋友圈简单布局)
来源:伯乐在线 - 夏天然后 链接:http://ios.jobbole.com/89298/ 点击 → 申请加入伯乐在线专栏作者 前言: 我模仿的是微博的布局所以也就没有 评论动态刷新cell. 1 ...
- 利用CSS简单布局的不同组合类型
关于CSS布局页面的简单组合方式: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...
- CSS学习之首页简单布局
作为一个PHPer,在前端方面javascript.jquery这些的日常工作还搞的定.可对于div+css这些东西可就头疼了,所以现在开始学习CSS 跟着燕十八的教程开始从最基础学起,首先练习一个简 ...
- 网页简单布局之结构与表现原则(HTML/CSS)
结构 样式 行为真正的分离 前端初级人员会在页面上单纯的用各个div把相关内容独立开: 前端中级人员明白相关属性的设置会给元素带来什么改变,从而减少div的书写: 前端高级人员会以及其简单的和稳定的方 ...
- 【ExtJS】简单布局应用
前几天学习了ExtJS的各种布局后,以下就是各种实践,从简单做起. 实现目的: 一个提交表单页,一个显示信息页,表单为个人基本资料输入,显示页为基本信息展示. 内容: 总体布局为border布局,展示 ...
- DIV+CSS 样式简单布局Tab 切换
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &l ...
随机推荐
- 20145318赵一Java课程总结
20145318赵一Java课程总结 每周读书笔记链接汇总 问卷调查 第1周读书笔记 第2周读书笔记 第3周读书笔记 第4周读书笔记 第5周读书笔记 第6周读书笔记 第7周读书笔记 第8周读书笔记 第 ...
- 关于卡尔曼滤波(Kalman Filter)的很好讲解
http://bilgin.esme.org/BitsAndBytes/KalmanFilterforDummies C#代码: double[] Data = new double[] { 0.39 ...
- [Chapter 3 Process]Practice 3.4 Describe what happens when a context switch occurs if the new context is already loaded into one of the register sets.
3.4 The Sun UltraSPARC processor has multiple register sets. Describe what happens when a context sw ...
- Java 第六章 循环结构2
循环结构 2 会使用 for 循环结构 会在程序中使用 break 和 continue for 比 while 更简洁 什么是 for 循环 ... 语法: for 循环的语法和执行顺序 备注:2条 ...
- hadoop 集群部署ganglia 监控服务与nagios 报警服务
1. 部署ganglia 服务 ganglia 涉及到的组件: 数据监测节点(gmond):这个部件装在需要监测的节点上,用于收集本节点的运行情况,并将这些统计信息传送到gmetad, ...
- CSS3中的Transition属性详解(贝赛尔曲线)
transition语法: transition : [<'transition-property'> || <'transition-duration'> || <'t ...
- WPF 虚拟键盘
之前做了一款WPF虚拟键盘,调用Win32的API,可以模拟键盘事件. 现将代码分享如下: 按键布局如下: <Button Name="> <StackPanel Orie ...
- [Leetcode][JAVA] Word Ladder
Given two words (start and end), and a dictionary, find the length of shortest transformation sequen ...
- phpcms后台登陆验证码不显示的解决方法
方法一:检查主机环境,是否已经开启gd库.可以用探针,或者检查php.ini文件,搜索extension=php_gd2.dll,检查前面是否有注释符号,去掉即可. 方法二:检查配置文件是否正确.打开 ...
- Zabbix3.0+CentOS7.0+MariaDB5.5监视服务器安装
本次安装采用: Centos7.0 Zabbix3.0 MariaDB5.5 ------------------- 2012/12/2更新 最新的Centos7.1或者Redhat7.1版本在最后 ...