代码如下:

 <?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">
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_columnSpan="4"
android:gravity="bottom|right"
android:background="#ccc"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="c"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="( )"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="÷"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="×"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="7"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="8"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="9"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="-"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="4"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="5"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="6"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="+"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="1"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="2"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="="
android:layout_columnWeight="1"
android:layout_rowSpan="2"
android:layout_rowWeight="1"
android:textSize="25sp"
android:layout_gravity="fill"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="0"
android:layout_columnWeight="1"
android:layout_columnSpan="2"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="."
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
</GridLayout>

效果如图:

网格布局能够实现纵向和竖向合并

Android——网格布局仿计算器的更多相关文章

  1. Android 网格布局 计算器

    <GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&quo ...

  2. Android 网格布局短信发送界面

    <?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:android=" ...

  3. android的布局-----GridLayout(网格布局)

    学习导图 (一)简介 网格布局由GridLayout所代表,在android4.0之后新增加的布局管理器,因此需要android4.0之后的版本中使用,如果在更早的平台使用该布局管理器,则需要导入相应 ...

  4. Android中帧布局-FrameLayout和网格布局-GridLayout

    帧布局-FrameLayout 一.概念 帧布局中,容器为每个加入其中的空间创建一个空白的区域(成为一帧).每个空间占据一帧,这些帧会按gravity属性自动对齐. 帧布局的效果是将其中的所有空间叠加 ...

  5. android——学习:网格布局——GridLayout

    Android一开始就提供了几种布局控件,如线性布局LinearLayout.相对布局RelativeLayout和表格布局TableLayout等,但在很多情况下,这些布局控件是不能满足要求的,因此 ...

  6. Android布局_网格布局GirdLayout

    自Android4.0版本后新增的GirdLayout网格布局(API 14) <?xml version="1.0" encoding="utf-8"? ...

  7. Android精通:TableLayout布局,GridLayout网格布局,FrameLayout帧布局,AbsoluteLayout绝对布局,RelativeLayout相对布局

    在Android中提供了几个常用布局: LinearLayout线性布局 RelativeLayout相对布局 FrameLayout帧布局 AbsoluteLayout绝对布局 TableLayou ...

  8. Android开发---网格布局案例

     Android开发---网格布局案例 效果图: 1.MainActivity.java package com.example.android_activity; import android.ap ...

  9. Android RecyclerView网格布局

    一个简单的网格布局activity_main.xml <?xml version="1.0" encoding="utf-8"?> <andr ...

随机推荐

  1. 在ubunut下使用pycharm和eclipse进行python远程调试

    我比较喜欢Pycharm,因为这个是JetBrains公司出的python IDE工具,该公司下的java IDE工具--IDEA,无论从界面还是操作上都甩eclipse几条街,但项目组里有些人使用e ...

  2. Windows Azure 实操 —— 迁移本地SharePoint服务器到Azure

    博客地址 http://blog.csdn.net/foxdave 注意:如果你是第二代虚拟机,那就别看这个了,老老实实在Azure上重新创建吧,Azure不支持第二代虚拟机. 写在之前,对Azure ...

  3. UVa 10318 Security Panel

    题意:给你一个3*3的翻转模版,深色部分表示翻转,浅色部分不变.然后你可以在r*c的矩形里依照模版进行翻转,要求所有点亮所有块.输出最小的步骤. 思路:有一点比较好想.每个块至多被翻转一次,翻两次的效 ...

  4. kali linux SET工具包

    尝试使用SET生成Teensy脚本是出现问题 1.出现错误 [!] Something went wrong, printing the error: [Errno 2] No such file o ...

  5. Android USB Connections Explained: MTP, PTP, and USB Mass Storage

    Android USB Connections Explained: MTP, PTP, and USB Mass Storage Older Android devices support USB ...

  6. (转)HTML 5离线存储之Web SQL

    原文:http://developer.51cto.com/art/201106/267357.htm HTML 5离线存储之Web SQL 2011-06-07 15:14 kkun kkun的博客 ...

  7. hdoj-2025

    #include "stdio.h"#include "string.h"void sort(char ch[],int count[],int n,int f ...

  8. Python入门(三,初级)

    一,函数调用 定义一个函数只给了函数一个名称,指定了函数里包含的参数,和代码块结构. 这个函数的基本结构完成以后,你可以通过另一个函数调用执行,也可以直接从Python提示符执行. 如下实例调用了pr ...

  9. Ubuntu 升级VisualBox后无法启动 Kernel driver not installed (rc=-1908)

    VisualBox之所以在Linux上比传统的VMware快得多,关键一点就是它和Linux内核的结合比较紧密,这也是开源的优点. 不过Linux内核更新很频繁,每次更新内核后启动VirtualBox ...

  10. PHP header()函数

    对header函数,我用得最多的就是跳转页面和设置字符集,其他的功能用得比较少. 一.设置字符集 其实我们用的最多的在在html代码当中的<meta>标签里面设置字符集.格式如下: < ...