Calculator源码分析

本文基于Android 5.1源码详细分析了Calculator应用。从AndroidManifest.xml开始,揭示了Calculator.java作为应用入口,深入探讨了activity_calculator.xml布局文件及其包含的display、numeric和operator布局。CalculatorPadViewPager的滑动效果和back键处理也在分析范围内。
摘要由CSDN通过智能技术生成

说明:该文章基于android 5.1的源码进行分析。

  1. calculator的效果图:
    这里写图片描述

  2. packages/apps/Calculator/AndroidManifest.xml
    我们先来看看这个文件AndroidManifest.xml
    <-manifest
    xmlns:android=”http://schemas.android.com/apk/res/android”
    package=”com.android.calculator2”>
    <-application
    android:icon=”@mipmap/ic_launcher_calculator”
    android:label=”@string/app_name”
    android:theme=”@style/CalculatorTheme”>
    <-activity
    android:name=”.Calculator”
    android:label=”@string/app_name”
    android:windowSoftInputMode=”stateAlwaysHidden”>
    <-intent-filter>
    <-action android:name=”android.intent.action.MAIN” />
    <-category android:name=”android.intent.category.LAUNCHER” />
    <-category android:name=”android.intent.category.APP_CALCULATOR” />
    <-/intent-filter>
    <-/activity>
    <-/application>
    <-/manifest>

我们可以看到,这个AndroidManifest.xml 中并没有太多的东西,只有对android:name=”.Calculator”这个是对我们有用的信息,在这里我们要使用的就是,Calculator.java是这个app的入口函数。

  1. packages/apps/Calculator/src/com/android/calculator2/Calculator.java
    我们接着来看下Calculator.java中的内容。
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_calculator);
    ……………….
    }
    setContentView(R.layout.activity_calculator)这里引用了布局文件activity_calculator.xml,
    <-LinearLayout
    xmlns:android=”http://schemas.android.com/apk/res/android”
    android:layout_width=”match_parent”
    android:layout_height=”match_parent”
    android:orientation=”vertical”>
    <-include
    layout=”@layout/display”
    android:layout_width=”match_parent”
    android:layout_height=”wrap_content” />
    <-com.android.calculator2.CalculatorPadViewPager
    android:id=”@+id/pad_pager”
    android:layout_width=”match_parent”
    android:layout_height=”0dip”
    android:layout_weight=”1”
    android:overScrollMode=”never”>
    <-LinearLayout
    android:layout_width=”match_parent”
    android:layout_height=”match_parent”>
    <-include layout=”@layout/pad_numeric” />
    <-include layout=”@layout/pad
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值