Android小项目——简单计算器的实现

Android实现简单计算器前言在学习了Android第一行代码的前三章后开始了自己的第一个android小项目,由于接触android时间不长,再加上个人审美能力较差,因此界面做的不是很好,大致可以体现出来一个计算器的界面。。。实现简单的计算器并不难,只要掌握了活动,布局以及控件的基本使用就可以开发出一个简单的android版计算器了界面部分我外层用的是外层相对布局,然后内层...
摘要由CSDN通过智能技术生成

Android实现简单计算器

前言

在学习了Android第一行代码的前三章后开始了自己的第一个android小项目,由于接触android时间不长,再加上个人审美能力较差,因此界面做的不是很好,大致可以体现出来一个计算器的界面。。。实现简单的计算器并不难,只要掌握了活动,布局以及控件的基本使用就可以开发出一个简单的android版计算器了

界面部分

我外层用的是外层相对布局,然后内层有四个线性布局加一个TextView控件,由于刚开始学,理解还不是特别深,因此布局这块写的可能感觉有点乱。。因为内层的线性布局采用了垂直布局,所以才写成了这样。。其实可以整体采用百分比布局或者外层垂直线性布局,内层水平线性布局,这样会比较清楚一点,以下是我的布局代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/jiemian"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/first"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_weight="1"
            android:orientation="vertical">

            <Button
                android:id="@+id/symbol_ac"
                android:layout_width="match_parent"
                android:layout_height="85dp"
                android:layout_weight="1"
                android:background="#f5f5f5"
                android:text="AC"
                android:textColor="#007dfe"
                android:textSize="24sp" />

            <Button
                android:id="@+id/number_7"
                android:layout_width="match_parent"
                android:layout_height="85dp"
                android:layout_weight="1"
                android:background="@android:color/white"
                android:text="7"
                android:textSize="24sp" />

            <Button
                android:id="@+id/number_4"
                android:layout_width="match_parent"
                android:layout_height="85dp"
                android:layout_weight="1"
                android:background="@android:color/white"
                android:text="4"
                android:textSize="24sp" />

            <Button
                android:id="@+id/number_1"
                android:layout_width="match_parent"
                android:layout_height="85dp"
                android:layout_weight="1"
                android:background="@android:color/white"
                android:text="1"
                android:textSize="24sp" />

            <Button
                android:id="@+id/symbol_left"
                android:layout_width="match_parent"
                android:layout_height="85dp"
                android:layout_weight="1"
                android:background="@android:color/white"
                android:text="("
                android:textSize="24sp" />

        </LinearLayout>

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/second"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_weight="1"
            android:orientation="vertical">

            <Button
                android:id="@+id/symbol_div"
                android:layout_width="match_parent"
                android:layout_height="85dp"
                android:layout_weight="1"
                android:background="#f5f5f5"
                android:text="/"
                android:textColor="#007dfe"
                android:textSize="24sp" />

            <Button
                android:id="@+id/number_8"
                android:layout_width="match_parent"
                android:layout_height="85dp"
                android:layout_weight="1"
                android:background="@android:color/white"
                android:text="8"
                android:textSize="24sp" />

            <Button
                android:id="@+id/number_5"
                android:layout_width="match_parent"
                android:layout_height="85dp"
                android:layout_weight="1"
                android:background="@android:color/white"
                android:text="5"
                android:textSize="24sp" />

            <Button
                android:id="@+id/number_2"
                android:layout_width="match_parent"
                android:layout_height="85dp"
                android:layout_weight="1"
                android:background="@android:color/white"
                android:text="2"
                android:textSize="24sp" />

            <Button
                android:id="@+id/number_0"
                android:layout_width="match_parent"
                
  • 8
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值