只实现了界面,没有实现具体功能
通过<Button />,<EditText />控件实现,采用<GridLayout />网格布局实现界面布局
效果图:
activity_main.xml中代码
<?xml version="1.0" encoding="utf-8"?>
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="7"
android:columnCount="4">
<EditText
android:hint="请输入"
android:gravity="bottom"
android:layout_height="100sp"
android:textSize="50sp"
android:layout_rowWeight="2"
android:layout_columnWeight="4"
android:layout_rowSpan="2"
android:layout_columnSpan="4"
android:layout_gravity="fill"
/>
<Button
android:text="清除"
android:layout_height="40sp"
android:textSize="30sp"
android:layout_rowWeight="1"
android:layout_columnWeight="4"
android:layout_rowSpan="1"
android:layout_columnSpan="4"
android:layout_gravity="fill" />
<Button
android:text="7"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="8"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="9"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="÷"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="4"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="5"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="6"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="*"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="1"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="2"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="3"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="-"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="."
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="0"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="+"
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
<Button
android:text="="
android:textSize="50sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
</GridLayout>
改软件名称
res——>values——>strings.xml文件中
<resources>
<string name="app_name">计算器</string>
</resources>