07、Android开发基础之编写计算器UI例子
来源:互联网 发布:信兰成 知乎 编辑:程序博客网 时间:2024/05/17 01:45
Android开发基础之编写计算器UI例子
思路分析
这个很简单,只要使用到我们前面学习的限行布局,或者表格布局就可以实现。
在视频中的话,我们是用线性布局,结合权重的方式实现的!
从上往下,然后每一行就也是一个线性布局嘛!
代码:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="80dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle" android:gravity="center" android:text="C" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle" android:gravity="center" android:text="+/-" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle" android:gravity="center" android:text="%" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle_oriange" android:gravity="center" android:text="/" android:textSize="30sp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="80dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle" android:gravity="center" android:text="1" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle" android:gravity="center" android:text="2" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle" android:gravity="center" android:text="3" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle_oriange" android:gravity="center" android:text="X" android:textSize="30sp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="80dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle" android:gravity="center" android:text="4" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle" android:gravity="center" android:text="5" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle" android:gravity="center" android:text="6" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle_oriange" android:gravity="center" android:text="--" android:textSize="30sp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="80dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle" android:gravity="center" android:text="7" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle" android:gravity="center" android:text="8" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle" android:gravity="center" android:text="9" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle_oriange" android:gravity="center" android:text="+" android:textSize="30sp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="80dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:background="@drawable/shape_rectangle" android:gravity="center_vertical" android:paddingLeft="40dp" android:text="0" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle" android:gravity="center" android:text="1" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/shape_rectangle_oriange" android:gravity="center" android:text="=" android:textSize="30sp"/> </LinearLayout></LinearLayout>
做出来是什么效果的呢?
视频下载地址
链接: https://pan.baidu.com/s/1qYLncw0 密码: s1s2
我们的网站社区:bbs.sunofbeaches.com
如果在学习中遇到什么问题,可以发帖子向大家提问哦!
也欢迎大家多写学习笔记,经验!!看到自己遇到的问题,会解的bug,相互帮助!
我们的口号是专为大学生解bug,专治各种不服!
阅读全文
0 0
- 07、Android开发基础之编写计算器UI例子
- Android开发之计算器
- 09、Android开发基础之计算器点击效果的实现
- Android开发计算器之布局
- Android开发之UI
- Android UI开发专题(二) 之绘图基础
- Android UI开发专题(二) 之绘图基础
- Android UI开发专题(二) 之绘图基础
- Android UI开发专题(二) 之绘图基础
- Android UI开发专题(二) 之绘图基础
- Android UI开发专题(二) 之绘图基础
- android基础之UI设计与开发一textView大全
- Android基础之UI设计与开发---------自定义进度条
- Android基础之UI设计与开发---------自定义进度条
- Android UI开发专题之界面设计【基础API】
- Android UI开发专题(二) 之绘图基础
- Android基础之UI设计与开发---------自定义进度条
- Android基础综合案例(七)《简易计算器UI界面设计》
- 数论——同余
- Hibernate缓存概述
- hostguest nativelangsys及uniform cui cross compile system
- ToLua原理和使用教程
- [LeetCode] 225. Implement Stack using Queues
- 07、Android开发基础之编写计算器UI例子
- 51Nod 1596 搬货物 二进制
- Shiro源码研究之ShiroFilterFactoryBean
- 面向对象语言特性之继承
- 人脸识别深度验证文章迁移
- CTR预估的几种方式
- 一个真实案例看懂 P2P供应链金融的玩法
- JPA
- leetcode题解-24. Swap Nodes in Pairs