安卓开发计算器开发

在这里插入图片描述

MainAtivity

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:background="@color/white"
    android:stretchColumns="*"
    android:layout_height="match_parent" >
    <TextView
        android:id="@+id/textViewDavid"
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:gravity="end"
        android:textSize="30sp"
        android:text="@string/text"/>

    <EditText
        android:id="@+id/editViewDavid"
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:gravity="end"
        android:inputType="text"
        android:textCursorDrawable="@null"
        android:textSize="30sp"
        tools:ignore="SpeakableTextPresentCheck" />
    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginTop="5dp"
        android:background="#000000"/>


    <TableRow
        android:id="@+id/tableRow1"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button7"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_7"
            android:textSize="25sp" />

        <Button
            android:id="@+id/button8"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:textSize="25sp"
            android:layout_height="match_parent"
            android:text="@string/_8" />

        <Button
            android:id="@+id/button9"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:textSize="25sp"
            android:layout_height="match_parent"
            android:text="@string/_9" />

        <Button
            android:id="@+id/buttonDivide"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/div"
            android:textSize="25sp" />

    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button4"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_4"
            android:textSize="25sp" />

        <Button
            android:id="@+id/button5"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_5"
            android:textSize="25sp" />

        <Button
            android:id="@+id/button6"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_6"
            android:textSize="25sp" />

        <Button
            android:id="@+id/buttonMultiply"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/mul"
            android:textSize="25sp" />

    </TableRow>

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button1"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_1"
            android:textSize="25sp" />

        <Button
            android:id="@+id/button2"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_2"
            android:textSize="25sp" />

        <Button
            android:id="@+id/button3"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_3"
            android:textSize="25sp" />

        <Button
            android:id="@+id/buttonMinus"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/sub"
            android:textSize="25sp" />

    </TableRow>

    <TableRow
        android:id="@+id/tableRow4"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button0"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_0"
            android:textSize="25sp" />

        <Button
            android:id="@+id/buttonPoint"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/point"
            android:textSize="25sp" />

        <Button
            android:id="@+id/buttonPlus"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/add"
            android:textSize="25sp" />

        <Button
            android:id="@+id/buttonEqual"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/equal"
            android:textSize="25sp" />

    </TableRow>

    <TableRow
        android:id="@+id/tableRow5"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/buttonClear"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_span="4"
            android:background="#3F51B5"
            android:text="@string/clear"
            android:textColor="#00C853"
            android:textSize="25sp" />

    </TableRow>

</TableLayout>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:background="@color/white"
    android:stretchColumns="*"
    android:layout_height="match_parent" >
    <TextView
        android:id="@+id/textViewDavid"
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:gravity="end"
        android:textSize="30sp"
        android:text="@string/text"/>

    <EditText
        android:id="@+id/editViewDavid"
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:gravity="end"
        android:inputType="text"
        android:textCursorDrawable="@null"
        android:textSize="30sp"
        tools:ignore="SpeakableTextPresentCheck" />
    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginTop="5dp"
        android:background="#000000"/>


    <TableRow
        android:id="@+id/tableRow1"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button7"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_7"
            android:textSize="25sp" />

        <Button
            android:id="@+id/button8"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:textSize="25sp"
            android:layout_height="match_parent"
            android:text="@string/_8" />

        <Button
            android:id="@+id/button9"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:textSize="25sp"
            android:layout_height="match_parent"
            android:text="@string/_9" />

        <Button
            android:id="@+id/buttonDivide"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/div"
            android:textSize="25sp" />

    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button4"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_4"
            android:textSize="25sp" />

        <Button
            android:id="@+id/button5"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_5"
            android:textSize="25sp" />

        <Button
            android:id="@+id/button6"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_6"
            android:textSize="25sp" />

        <Button
            android:id="@+id/buttonMultiply"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/mul"
            android:textSize="25sp" />

    </TableRow>

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button1"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_1"
            android:textSize="25sp" />

        <Button
            android:id="@+id/button2"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_2"
            android:textSize="25sp" />

        <Button
            android:id="@+id/button3"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_3"
            android:textSize="25sp" />

        <Button
            android:id="@+id/buttonMinus"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/sub"
            android:textSize="25sp" />

    </TableRow>

    <TableRow
        android:id="@+id/tableRow4"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button0"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/_0"
            android:textSize="25sp" />

        <Button
            android:id="@+id/buttonPoint"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/point"
            android:textSize="25sp" />

        <Button
            android:id="@+id/buttonPlus"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/add"
            android:textSize="25sp" />

        <Button
            android:id="@+id/buttonEqual"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/equal"
            android:textSize="25sp" />

    </TableRow>

    <TableRow
        android:id="@+id/tableRow5"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/buttonClear"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_span="4"
            android:background="#3F51B5"
            android:text="@string/clear"
            android:textColor="#00C853"
            android:textSize="25sp" />

    </TableRow>

</TableLayout>

string.xml

<resources>
    <string name="app_name">CalculatorDemo</string>
    <string name="text">TEXT</string>
    <string name="edit">Edit</string>
    <string name="_0">0</string>
    <string name="_1">1</string>
    <string name="_2">2</string>
    <string name="_3">3</string>
    <string name="_4">4</string>
    <string name="_5">5</string>
    <string name="_6">6</string>
    <string name="_7">7</string>
    <string name="_8">8</string>
    <string name="_9">9</string>
    <string name="div">/</string>
    <string name="mul">*</string>
    <string name="sub">-</string>
    <string name="point">.</string>
    <string name="add">+</string>
    <string name="equal">=</string>
    <string name="clear">clear</string>
</resources>

猜你喜欢

转载自blog.csdn.net/weixin_44927247/article/details/120140975