步骤 1: 设置Android Studio项目
创建一个新的Android项目,选择Java作为编程语言。
步骤 2: 设计用户界面
打开activity_main.xml
文件,在res/layout
目录下,设计你的计算器用户界面。这个例子使用了LinearLayout
来排列两个EditText
输入框和几个按钮。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<EditText
android:id="@+id/number1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="Enter number"/>
<EditText
android:id="@+id/number2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="Enter number"/>
<Button
android:id="@+id/addButton