Android原生开发之简单计算器的界面布局

1.界面展示

2.布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#EEEEEE"
    android:padding="5dp">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/simple_calculator"
            android:gravity="center"
            android:textColor="@color/black"
            android:textSize="20sp"/>
        <TextView
            android:id="@+id/tv_result"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:lines="3"
            android:text="0"
            android:textColor="@color/black"
            android:textSize="25sp"
            android:gravity="right|bottom"/>
        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:columnCount="4"
            android:rowCount="5">
            <Button
                android:id="@+id/btn_cancel"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/cancel"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_divide"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/divide"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_multiply"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/multiply"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_clear"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/clear"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_seven"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/seven"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_eight"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/eight"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_nine"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/nine"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_plus"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/plus"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_four"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/four"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_five"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/five"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_six"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/six"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_minus"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/minus"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_one"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/one"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_two"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/two"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_three"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/three"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <ImageButton
                android:id="@+id/genhao"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:scaleType="fitXY"
                android:src="@drawable/genhao"/>
            <Button
                android:id="@+id/btn_reciprocal"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/reciprocal"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_zero"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/zero"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_dot"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/dot"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
            <Button
                android:id="@+id/btn_equal"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_columnWeight="1"
                android:gravity="center"
                android:text="@string/equal"
                android:textColor="@color/black"
                android:textSize="@dimen/button_font_size"/>
        </GridLayout>
    </LinearLayout>
</ScrollView>
</LinearLayout>

 3.string.xml

<resources>
    <string name="app_name">Calculator</string>
    <string name="simple_calculator">简单计算器</string>
    <string name="cancel">CE</string>
    <string name="divide">➗</string>
    <string name="multiply">✖</string>
    <string name="clear">C</string>
    <string name="seven">7</string>
    <string name="eight">8</string>
    <string name="nine">9</string>
    <string name="plus">➕</string>
    <string name="four">4</string>
    <string name="five">5</string>
    <string name="six">6</string>
    <string name="minus">➖</string>
    <string name="one">1</string>
    <string name="two">2</string>
    <string name="three">3</string>
    <string name="reciprocal">1/X</string>
    <string name="zero">0</string>
    <string name="dot">.</string>
    <string name="equal">=</string>
</resources>

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Breathe301

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值