计算器布局

这里写图片描述

布局做个记录吧

<?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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.jane.simplecalculator.MainActivity">

    <TableRow
        android:layout_width="match_parent"
        android:layout_gravity="center"
        android:layout_weight="1">
        <EditText
            android:id="@+id/output"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="right|center_vertical"
            android:lines="1"
            android:textSize="48sp"
            android:layout_weight="1"
            android:background="@color/green"/>
    </TableRow>

    <TableRow
        android:layout_weight="1"
        android:gravity="center">
        <LinearLayout android:layout_weight="4"
            android:layout_height="match_parent">
            <Button
                android:id="@+id/one"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="1"
                android:textSize="30sp"/>

            <Button
                android:id="@+id/two"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="2"
                android:textSize="30sp"/>

            <Button
                android:id="@+id/three"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="3"
                android:textSize="30sp"/>

            <Button
                android:id="@+id/plus"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="+"
                android:textSize="30sp"/>
        </LinearLayout>
    </TableRow>

    <TableRow
    android:layout_weight="1"
        android:gravity="center">
    <LinearLayout
        android:layout_height="match_parent"
        android:layout_weight="4">
        <Button
            android:id="@+id/four"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="4"
            android:textSize="30sp"/>

        <Button
            android:id="@+id/five"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="5"
            android:textSize="30sp"/>

        <Button
            android:id="@+id/six"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="6"
            android:textSize="30sp"/>

        <Button
            android:id="@+id/subtract"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="-"
            android:textSize="30sp"/>
    </LinearLayout>
</TableRow>
    <TableRow
        android:layout_weight="1"
        android:gravity="center">
        <LinearLayout
            android:layout_height="match_parent"
            android:layout_weight="4">
            <Button
                android:id="@+id/seven"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="7"
                android:textSize="30sp"/>

            <Button
                android:id="@+id/eight"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="8"
                android:textSize="30sp"/>

            <Button
                android:id="@+id/nine"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="9"
                android:textSize="30sp"/>

            <Button
                android:id="@+id/multiply"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="*"
                android:textSize="30sp"/>
        </LinearLayout>
    </TableRow>
    <TableRow
        android:layout_weight="1"
        android:gravity="center">
        <LinearLayout
            android:layout_height="match_parent"
            android:layout_weight="4">
            <Button
                android:id="@+id/clear"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="清空"
                android:textSize="30sp"/>

            <Button
                android:id="@+id/zero"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="0"
                android:textSize="30sp"/>

            <Button
                android:id="@+id/equal"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="="
                android:textSize="30sp"/>

            <Button
                android:id="@+id/divide"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="/"
                android:textSize="30sp"/>
        </LinearLayout>
    </TableRow>
</TableLayout>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值