Android计算器界面布局

- 这是一个Android的计算器界面布局,仅布局,不实现功能

目录


1. 界面布局分析
  • 效果图
  • 这个界面总体是垂直分布,从上到下共7行
  • 第1、2行是输入、输出框,这里采用的是EditText
  • 第3到7行是输入按钮,每行水平分布
  • 第3到6行行内每个Button大小相同
  • 第7行的Button“0”占了两个位置

由此我们可以简单总结出,总框架权重设置为7,每行占总权重的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:weightSum="7">				#总权重为7


    <EditText							#第一个输入框
        android:id="@+id/input"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#aaaaaa"
        android:layout_weight="1"/>		#占总权重7的1(7.1)

    <EditText							#第二个文本框
        android:id="@+id/output"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#cccccc"
        android:layout_weight="1"/>		#占总权重7的1(7.2)

    <LinearLayout						#第一行Button
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"		#此行占总权重的1(7.3)

        android:orientation="horizontal"	#控件内容水平排列
        android:weightSum="5">				#控件有5个button,设置行权重5

        <Button								#第一行第一个Button
            android:id="@+id/button_clear"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"		#占父LinearLayout权重的1(5.1)
            android:text="AC"
            android:textSize="25sp" />

        <Button								#第一行第二个Button
            android:id="@+id/button_delete"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"		#占父LinearLayout权重的1(5.2)
            
  • 11
    点赞
  • 65
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值