android学习--adroid线性布局 一个计算器的布局

使用Android studio 3.0.1实现简单计算器 计算器是日常常用的计算工具,此次介绍一种由Android studio实现的简易计算器,能够实现基本的加减乘除,删除和清空功能。 实现效果图如下: 首先介绍一下使用的资源文件: 1.res -> values -> colors.xml文件,可以默认,可以自己加入颜色样本,只是为了方便色号对比和查询,可自行选择喜欢的颜色。 <?xml version="1.0" e... 阅读详情

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    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.uidemo01.MainActivity" 
    android:background="#ffffff">
    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        
        <EditText android:id="@+id/msg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>        
    </LinearLayout>
    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="mc"
            android:layout_weight="1"/>
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="m+"
            android:layout_weight="1"/>
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="m-"
            android:layout_weight="1"/>
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="mr"
            android:layout_weight="1"/>
    </LinearLayout>
    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="C"
            android:layout_weight="1"/>
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="+/-"
            android:layout_weight="1"/>
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="/"
            android:layout_weight="1"/>
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="*"
            android:layout_weight="1"/>
    </LinearLayout>
     <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="7"
            android:layout_weight="1"/>
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="8"
            android:layout_weight="1"/>
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="9"
            android:layout_weight="1"/>
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="-"
            android:layout_weight="1"/>
    </LinearLayout>
    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="4"
            android:layout_weight="1"/>
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="5"
            android:layout_weight="1"/>
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="6"
            android:layout_weight="1"/>
        <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="+"
            android:layout_weight="1"/>
    </LinearLayout>
    
    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout android:orientation="vertical"
            android:layout_weight="3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            
            <LinearLayout android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
               
                <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="1"
            android:layout_weight="1"/>
                <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="2"
            android:layout_weight="1"/>
                <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="3"
            android:layout_weight="1"/>
            </LinearLayout>
            
            <LinearLayout android:orientation="horizontal"                         
                           android:layout_width="match_parent"
                            android:layout_height="wrap_content">
                <Button android:layout_width="0px"
            android:layout_height="wrap_content"
            android:text="0"
            android:layout_weight="2"/>
                <Button android:layout_width="0px"
            android:layout_height="wrap_content"
            android:text="."
            android:layout_weight="1"/>
                </LinearLayout>
                
        </LinearLayout>
        <LinearLayout android:orientation="horizontal"
            android:layout_width="wrap_content" 
            android:layout_weight="1"
            android:layout_height="match_parent">
            <Button android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="="
            android:layout_weight="1"/>
            
        </LinearLayout>
    </LinearLayout>
    

</LinearLayout>

最后效果


Android布局和控件 往期回顾: 开发第一个Android程序 JAVA_IO原理、分类以及常见用法 安卓逆向交流学习:342647370 vx:yijin1108an 一: Adroid布局 有人形象地比喻,Android开发中的布局就相当于一栋建筑的外观架构。布局用得好,这栋建筑的外观才美观高大上。 1.Android布局管理器: Android布局管理器是一个界面控件,所有的布局管理器都是ViewGroup类的子类,都是可以当做容器类来使用的。因此一个布局管理器中可以嵌套其他的布局管理器,布局管理器的层级关系,如下所示。 阅读详情

相关推荐

基于Android的计算器布局

简单的计算器布局,适合初学者,可以用真的可以用,适合

Android简易计算器(一)——线性布局实现

  最近在学安卓的相关知识,第一个demo做了一个简易计算器,功能仿手机上自带的计算器,没有加括号,简单的四则运算,支持长表达式运算。 (左侧是 oppo r9自带计算器,右侧是我的效果图) 实现布局的方式有很多,这里我采用的是线性嵌套布局,下面嵌套示意图(不同的颜色表达不同的层级): 实现代码: &amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;u...

zwkkkk1的博客 1万+

稳压电源的隐形战场:动态特性如何影响你的嵌入式系统稳定性

本文深入探讨了稳压电源动态特性对嵌入式系统稳定性的关键影响,分析了HT7533和AMS1117等稳压芯片在输入阶跃响应和负载瞬态响应方面的性能差异。通过实测案例展示了不同场景下的动态特性表现,并提供了针对工业控制、IoT设备和射频系统的选型指南与优化策略,帮助工程师解决电源相关的隐蔽故障。

weixin_29204205的博客 609

Android实现计算器布局(四种布局方式)之LinearLayout线性布局

用LinearLayout实现计算器的布局主要使用它属性: android:orientation=”vertical” android:orientation=”horizontal”(通常水平

Julse的博客 9922

esim分布式云卡池技术

eSIM卡,即Embedded-SIM,嵌入式SIM卡。eSIM卡的概念就是将传统SIM卡直接嵌入到设备芯片上,而不是作为独立的可移除零部件加入设备中,用户无需插入物理SIM卡。这一做法将允许用户更加灵活的选择运营商套餐,或者在无需解锁设备、购买新设备的前提下随时更换运营商。未来通用的eSIM标准建立将为普通消费者、企业用户节省更多移动设备使用成本,并带来更多的便利、安全性。 2018年 3月7日,中国联通宣布,正式在上海、天津、广州、深圳、郑州、长沙6座城市率先启动“eSIM一号双终端”业务的办理。[.

著名博客 3708

光模块封装工艺简介

光模块按照部件可以分为芯片、光器件、光模块三个层级;按照应用领域大概可分为电信应用、数通应用两个领域;按照内部器件的封装工艺可分为TO、Box、COB三大类。 但是,无论是哪种类型的光模块,其生产工艺基本上可以分为封装、测试两大块。   那什么叫做器件封装呢?我的理解器件封装就是利用胶水、焊料、机械、热量等手段把器件按照一定的先后次序结合形成一个整体的过程,就好像早上吃的煎饼,把面粉、鸡蛋、脆饼、烤肠、葱花等这些“器件”,按照一定的顺序,通过食用油、甜面酱、加热、卷起来等手段结合到一起,形成了美味的

qq_33253182的博客 2830

Android-计算器的实现(界面布局,计算逻辑处理)

源码下载 闲来无事,用android做一个计算器玩玩,想着做一个私密空间,表面是计算器,按下原先设定的算式后可以跳转到私密界面,当想想有些费事,以后若还有闲散时间,再来实现。 我实现了更完善的计算器,功能更多,逻辑更完善,欢迎访问!点击这里 界面是这样的,采用了GridLayout布局,很容易实现。代码如下 <?xml version="1.0" enc...

我要出家当道士 2万+

【数字逻辑电路课程设计】多功能数码管时钟VHDL+quartus II-EP1C12F324C8+源码+付费资源

我希望需要我这篇文章的是正常学习数字逻辑课程且正在设计数码管时钟的同学。我个人不推荐直接获取源代码,因此我另有一份付费资源是完整源代码;我推荐各位去研究我代码的逻辑尝试自己书写属于自己的代码,因此我保留了注释但隐去了变量。由于时间有限,我的设计不够完美,仍有很多缺陷,我将我的展望写在后面,各位可以尝试实现。我不为难同学,作为同学我理解各位设计的辛苦,因此如果有需要,私信我提供隐去敏感信息的学生证照片可直接获取源代码。

WannaFlysyx的博客 1534

android studio开发计算器

一个简易的计算器,边学边写,还有很多不足希望多多指教 先看布局,整体线性布局,上面两个TextView,一个存放计算过程,一个给出结果,然后一个table布局,button没有声明在xml里,用Java写的,好处是比较方便,坏处是我不会怎么让button适应屏幕,看起来有点丑。 <?xml version="1.0" encoding="utf-8"?> <android.sup...

tjdxwwj的博客 1646

CLAHE 算法学习 matlab

概念可参考: CLAHE (Contrast Limited Adaptive Histogram Equalization)算法学习CLAHE具体实现主要包括6个步骤。1):分块。将输入图像划分为大小相等的不重叠子块,每个子块含有的像素数为M。参考示例为8×8块。 2):计算子块直方图。 3):计算剪切阈值clipLimit 4):像素点重分配。对每个子块,使用步骤三中多余的像素重新分配。 5):直方图均衡。 6):像素点灰度值重构。(源码中采用了双线性插值) http://www.realtimer

baidu_34971492的博客 4253

硬件工程师笔试面试高频考点汇总——(2025版)

《硬件工程师笔试面试知识汇总》一文系统梳理了硬件领域的核心知识体系,涵盖电子器件、模拟电路、数字电路等模块。文章详细解析了电阻、电容、电感等基础元件的选型与应用,深入探讨了三极管、MOS管等半导体器件的工作原理,并对比分析了DCDC与LDO等电源方案。在电路设计方面,提供了滤波器、放大器等实用电路的设计方法与仿真案例,同时包含UART、I2C等通信协议的实现要点。文章还整合了戴维宁定理等电路分析理论,并附有美团、联想等名企真题解析。通过器件特性、电路设计、企业真题三维度内容,为硬件工程师构建了完整的知识框架

XU157303764的博客 1万+

Android Studio制作简易计算器源代码及详解

废话不多说,下图是计算器截图(布局是可以更改的): 下面是我创建计算器项目的代码目录结构: 下面分享的是activity_main.xml中的源代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.andro

℃江 11万+

深度测评:Accio Work——目前普通用户最友好的多 Agent 协同工具

摘要:Accio Work是阿里国际站推出的多Agent协同工具,通过借鉴古代"三省六部制"构建高效协作框架。该工具支持主流大模型,可配置专业Agent角色,实现40分钟内完成复杂产品PRD等高效协作。其亮点在于直观的UI设计和流程驱动机制,能强制各Agent从专业视角深度思考。虽然超长对话稳定性有待优化,但作为目前最用户友好的多Agent工具,显著降低了构建复杂AI团队的门槛,成为提升个人和小微企业生产力的利器。

Maynor的博客 1738

安卓仿计算器布局代码

http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff808080" android:orientation="vertical" > android:id="@+

sunkailu的专栏 1386

MATLAB应用实战系列(七十七)-基于长时间序列栅格数据的MK检验

1 MK检验介绍 MK检验是曼-肯德尔法,又称Mann—Kenddall 检验法,是一种气候诊断与预测技术,应用Mann-Kendall检验法可以判断气候序列中是否存在气候突变,如果存在,可确定出突变发生的时间。Mann-Kendall检验法也经常用于气候变化影响下的降水、干旱频次趋势检测。目前常用于长时间序列的栅格数据的显著性检验,在植被覆盖度,NDVI,NPP等方面尤为常见。 该检验功能强大,不需要样本遵从一定的分布,部分数据缺失不会对结果造成影响,不受少数异常值的干扰,适用性强。不但可以检验时

wenyusuran的专栏 6291

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Android实现计算器布局(四种布局方式)之RelativeLayout相对布局

RelativeLayout相对布局 其他三种 1.LinearLayout线性布局实现计算器界面布局 2.TableLayout表格布局实现计算器界面布局 3.GridLayout网格布局实现计算器界面布局 用RelativeLayout相对布局解决计算器布局问题比较简单,用鼠标直接拖拽就能达到很好的布局效果效果图: outline视图: RelativeLayo

Julse的博客 9552

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Android计算器布局

650) this.width=650;" title="20120312_3b568dab8aab1733e5f82jHd92AAKaYa.jpg" src="http://s3.51cto.com/wyfs02/M02/1A/41/wKioL1MUjNqyYYz7AALrmkQJxfs304.jpg" alt="wKioL1MUjNqyYYz7AALrmkQJxfs304.jpg" />  

joker_321的专栏 638

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

第一个Android项目——计算器

第一个Android项目——计算器 效果 开始学Android一两个星期了,学习了一下基本的Activity、简单控件及几个简单布局,打算找个东西来练练手,于是就选择发计算器。关于计算器中用到的四则运算在上一篇博客表达式(四则运算)计算的算法中已经讲了。这里不再赘述。 先看一下要达成的效果图: 图1 这里只用到了一个Activity,有EditT...

he91-com 500

Python App 爬虫:某美食APP 菜谱爬取

多线程爬取美食APP菜谱分类中的菜谱数据,并存到mongoDB。

ziazan的博客 2261

~取反操作符

原码、反码、补码的计算方式~(取反操作符)例子1: ~5 = -6 计算公式: -(x + 1) 计算过程:5 原码: 0 000 0101 反码: 0 000 0101 补码: 0 000 0101 ~5(按照5的补码取反) 补码: 1 111 1010 反码: 1 111 1001 原码: 1 000 0110 得到结果:-5例子1: ~-5 = 4 计算公式: -(x + 1) 计算过

ziazan的博客 1632

开始学习C#,用c#写冒泡,杨辉三角

C#中定义数组的方式很不一样

ziazan的博客 920

前端跨域方式大汇总

跨域问题在几次的面试中,都被问到前端的跨域方案问题。在实际的项目中,也总是遇到。这篇文章是在看那些年,那些跨域问题 后的笔记。在这篇文章中理解什么是跨域 JavaScript跨域(1):什么是跨域,如何跨域 具体策略限制情况可看下表 URL 说明 允许通信

ziazan的博客 786

React笔记-一些要注意的点

在React中要注意在componentWillUpadate 中不能用 this.setState() 方法。 componentWillUpadate问题的出现在学习的时候,有一个例子的要求是, 使用componentWillUpdate()方法修改示例代码,使时钟在秒为0时显示为红色字体!

ziazan的博客 669

javascript 中存在哪些类型转换

在看《jQuery技术内幕》的时候,看到一句话: ……这里使用等同运算符(===)来避免类型转换。 我在想javascript 中存在哪些类型转换呢?javascript 中的数据类型 javascript 中的原始类型javascript 中有5种原始类型。 == 和 === 的区别

ziazan的博客 610

[学习记录]Node event loop 总结流程图

node event loop 为什么“在I/O事件的回调中,setImmediate方法的回调永远在timer的回调前执行 详解JavaScript中的Event Loop(事件循环)机制 根据内容输出的流程图 遗留的问题 为什么“在I/O事件的回调中,setImmediate方法的回调永远在timer的回调前执行”?

ziazan的博客 577
上一篇: 开始学习C#,用c#写冒泡,杨辉三角
下一篇: CheckBoxList横向排列
ziazan
博客等级 码龄12年 49粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值