承接上篇博客,每到一个阶段,我们就用一个项目总结我们学习到的内容,今天我们就一起继续完成一个拥有记忆功能的简单计算器,首先我们先看下计算器布局:
布局
计算主页面:
历史记录查询页面:
自定义标题:
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="< 返回"
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: