Android开发学习(9)记忆功能计算器

本文介绍了如何使用Android开发一个具备记忆功能的计算器应用。通过布局设计、Activity管理和SQLite数据库实现计算器的主页面、历史记录查询等功能。源码链接提供,便于读者深入学习。
摘要由CSDN通过智能技术生成

承接上篇博客,每到一个阶段,我们就用一个项目总结我们学习到的内容,今天我们就一起继续完成一个拥有记忆功能的简单计算器,首先我们先看下计算器布局:

布局

计算主页面:

calc_main

历史记录查询页面:

calc_history

自定义标题:

head.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/layout_titlebar"
                android:layout_width="match_parent"
                android:layout_height="52dp"
                android:background="#ed4255" >

    <Button
            android:id="@+id/button_backward"
            android:layout_width="60dp"
            android:layout_height="match_parent"
            android:background="#ed4255"
            android:drawablePadding="6dp"
            android:ellipsize="end"
            android:onClick="back"
            android:gravity="center"
            android:paddingLeft="5dp"
            android:singleLine="true"
            android:text="&lt; 返回"
            android:textColor="#ffffffff"
            android:textSize="20dp"
            android:visibility="visible" />

    <TextView
            android:id="@+id/text_title"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:ellipsize="marquee"
            android:gravity="center_horizontal|center"
            android:singleLine="true"
            android:text="XS-APP"
            android:textColor="#ffffffff"
            android:textSize="20dp" />



    <Button
            android:id="@+id/button_forward"
            android:layout_width="60dp"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:drawablePadding="6dp"
            android:background="#ed4255"
            android:ellipsize="end"
            android:gravity="center"
            android:paddingLeft="5dp"
            android:singleLine="true"
            android:text="···"
            android:textColor="#ffffffff"
            android:textSize="30dp"
            android:visibility="invisible" />

</RelativeLayout>

计算器主页面:

calc.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:background="#fafcfa"
              android:layout_height="match_parent">


    <include layout="@layout/head" />

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <TextView
                android:id="@+id/print_show"
                android:layout_width="0dp"
                android:layout_height="@dimen/view_size_150"
                android:layout_weight="1"
                android:background="@color/background_head"
                android:gravity="left"
                android:padding="@dimen/view_space_10"
                android:textSize="@dimen/font_size_20" />



    </LinearLayout>


    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <Button
                android:id="@+id/key_C"
                style="@style/keyStyle"
                android:text="C" />

        <View
                android:layout_width="@dimen/line_size_.5"
                android:layout_height="match_parent"
                android:background="@color/white" />

        <Button
                android:id="@+id/key_clean"
                style="@style/keyStyle"
                android:text="清除" />

        <View
                android:layout_width="@dimen/line_size_.5"
                android:layout_height="match_parent"
                android:background="@color/white" />
        <Button
                android:id="@+id/key_hisrory"
                style="@style/keyStyle"
                android:text="历史" />

    </LinearLayout>


    <View
            android:layout_width="wrap_content"
            android:layout_height="@dimen/line_size_.5"
            android:background="@color/white" />

    <LinearLayout
            android:
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值