UI事件 计算器界面

1.MainActivity.java

  1 package com.example.administrator.testapp2;
  2
  3 import android.support.v7.app.AppCompatActivity;
  4 import android.os.Bundle;
  5 import android.view.View;
  6 import android.widget.Button;
  7 import android.widget.TextView;
  8
  9 public class MainActivity extends AppCompatActivity {
 10
 11     TextView tv_1;
 12
 13     Button bt1;
 14     Button bt2;
 15     Button bt3;
 16     Button bt4;
 17     Button bt5;
 18     Button bt6;
 19     Button bt7;
 20     Button bt8;
 21     Button bt9;
 22     Button bt0;
 23     Button bt_add;
 24     Button bt_jian;
 25     Button bt_cheng;
 26     Button bt_chu;
 27     Button bt_kuohao;
 28     Button bt_dian;
 29
 30     @Override
 31     protected void onCreate(Bundle savedInstanceState) {
 32         super.onCreate(savedInstanceState);
 33         setContentView(R.layout.activity_main);
 34
 35         tv_1 = (TextView)findViewById(R.id.tv_1);
 36
 37         bt0 = (Button)findViewById(R.id.bt0);
 38         bt0.setOnClickListener(new View.OnClickListener() {
 39             @Override
 40             public void onClick(View v) {
 41                 tv_1.setText("0");
 42             }
 43         });
 44         bt1 = (Button)findViewById(R.id.bt1);
 45         bt1.setOnClickListener(new View.OnClickListener() {
 46             @Override
 47             public void onClick(View v) {
 48                 tv_1.setText("1");
 49             }
 50         });
 51         bt2 = (Button)findViewById(R.id.bt2);
 52         bt2.setOnClickListener(new View.OnClickListener() {
 53             @Override
 54             public void onClick(View v) {
 55                 tv_1.setText("2");
 56             }
 57         });
 58         bt3 = (Button)findViewById(R.id.bt3);
 59         bt3.setOnClickListener(new View.OnClickListener() {
 60             @Override
 61             public void onClick(View v) {
 62                 tv_1.setText("3");
 63             }
 64         });
 65         bt4 = (Button)findViewById(R.id.bt4);
 66         bt4.setOnClickListener(new View.OnClickListener() {
 67             @Override
 68             public void onClick(View v) {
 69                 tv_1.setText("4");
 70             }
 71         });
 72         bt5 = (Button)findViewById(R.id.bt5);
 73         bt5.setOnClickListener(new View.OnClickListener() {
 74             @Override
 75             public void onClick(View v) {
 76                 tv_1.setText("5");
 77             }
 78         });
 79         bt6 = (Button)findViewById(R.id.bt6);
 80         bt6.setOnClickListener(new View.OnClickListener() {
 81             @Override
 82             public void onClick(View v) {
 83                 tv_1.setText("6");
 84             }
 85         });
 86         bt7 = (Button)findViewById(R.id.bt7);
 87         bt7.setOnClickListener(new View.OnClickListener() {
 88             @Override
 89             public void onClick(View v) {
 90                 tv_1.setText("7");
 91             }
 92         });
 93         bt8 = (Button)findViewById(R.id.bt8);
 94         bt8.setOnClickListener(new View.OnClickListener() {
 95             @Override
 96             public void onClick(View v) {
 97                 tv_1.setText("8");
 98             }
 99         });
100         bt9 = (Button)findViewById(R.id.bt9);
101         bt9.setOnClickListener(new View.OnClickListener() {
102             @Override
103             public void onClick(View v) {
104                 tv_1.setText("9");
105             }
106         });
107         bt_add = (Button)findViewById(R.id.bt_add);
108         bt_add.setOnClickListener(new View.OnClickListener() {
109             @Override
110             public void onClick(View v) {
111                 tv_1.setText("+");
112             }
113         });
114         bt_jian = (Button)findViewById(R.id.bt_jian);
115         bt_jian.setOnClickListener(new View.OnClickListener() {
116             @Override
117             public void onClick(View v) {
118                 tv_1.setText("-");
119             }
120         });
121         bt_cheng = (Button)findViewById(R.id.bt_cheng);
122         bt_cheng.setOnClickListener(new View.OnClickListener() {
123             @Override
124             public void onClick(View v) {
125                 tv_1.setText("X");
126             }
127         });
128         bt_chu = (Button)findViewById(R.id.bt_chu);
129         bt_chu.setOnClickListener(new View.OnClickListener() {
130             @Override
131             public void onClick(View v) {
132                 tv_1.setText("÷");
133             }
134         });
135         bt_dian = (Button)findViewById(R.id.bt_dian);
136         bt_dian.setOnClickListener(new View.OnClickListener() {
137             @Override
138             public void onClick(View v) {
139                 tv_1.setText(".");
140             }
141         });
142         bt_kuohao = (Button)findViewById(R.id.bt_kuohao);
143         bt_kuohao.setOnClickListener(new View.OnClickListener() {
144             @Override
145             public void onClick(View v) {
146                 tv_1.setText("()");
147             }
148         });
149     }
150 }

2.jsq.xml

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3     android:layout_width="match_parent"
  4     android:layout_height="match_parent"
  5     android:rowCount="5"
  6     android:columnCount="4">
  7 <TextView
  8     android:layout_width="match_parent"
  9     android:layout_height="220dp"
 10     android:layout_columnSpan="4"
 11     android:textSize="60dp"
 12     android:gravity="right|bottom"
 13     android:text="6"
 14     android:textColor="#0F0"
 15     android:paddingRight="10dp"
 16     android:id="@+id/tv_1"/>
 17
 18     <Button
 19         android:layout_width="wrap_content"
 20         android:layout_height="wrap_content"
 21         android:text="CE"
 22         android:layout_rowWeight="1"
 23         android:id="@+id/bt_CE"
 24         android:textSize="25sp"
 25         android:layout_columnWeight="1"/>
 26     <Button
 27         android:layout_width="wrap_content"
 28         android:layout_height="wrap_content"
 29         android:text="←"
 30         android:id="@+id/bt_qc"
 31         android:textSize="25sp"
 32         android:layout_rowWeight="1"
 33         android:layout_columnWeight="1"/>
 34     <Button
 35         android:layout_width="wrap_content"
 36         android:layout_height="wrap_content"
 37         android:text="÷"
 38         android:id="@+id/bt_chu"
 39         android:textSize="25sp"
 40         android:layout_rowWeight="1"
 41         android:layout_columnWeight="1"/>
 42     <Button
 43         android:layout_width="wrap_content"
 44         android:layout_height="wrap_content"
 45         android:text="X"
 46         android:id="@+id/bt_cheng"
 47         android:textSize="25sp"
 48         android:layout_rowWeight="1"
 49         android:layout_columnWeight="1"/>
 50     <Button
 51         android:layout_width="wrap_content"
 52         android:layout_height="wrap_content"
 53         android:text="7"
 54         android:id="@+id/bt7"
 55         android:textSize="25sp"
 56         android:layout_rowWeight="1"
 57         android:layout_columnWeight="1"/>
 58     <Button
 59         android:layout_width="wrap_content"
 60         android:layout_height="wrap_content"
 61         android:text="8"
 62         android:id="@+id/bt8"
 63         android:textSize="25sp"
 64         android:layout_rowWeight="1"
 65         android:layout_columnWeight="1"/>
 66     <Button
 67         android:layout_width="wrap_content"
 68         android:layout_height="wrap_content"
 69         android:text="9"
 70         android:id="@+id/bt9"
 71         android:textSize="25sp"
 72         android:layout_rowWeight="1"
 73         android:layout_columnWeight="1"/>
 74     <Button
 75         android:layout_width="wrap_content"
 76         android:layout_height="wrap_content"
 77         android:text="-"
 78         android:id="@+id/bt_jian"
 79         android:textSize="25sp"
 80         android:layout_rowWeight="1"
 81         android:layout_columnWeight="1"/>
 82     <Button
 83         android:layout_width="wrap_content"
 84         android:layout_height="wrap_content"
 85         android:text="4"
 86         android:id="@+id/bt4"
 87         android:textSize="25sp"
 88         android:layout_rowWeight="1"
 89         android:layout_columnWeight="1"/>
 90     <Button
 91         android:layout_width="wrap_content"
 92         android:layout_height="wrap_content"
 93         android:text="5"
 94         android:id="@+id/bt5"
 95         android:textSize="25sp"
 96         android:layout_rowWeight="1"
 97         android:layout_columnWeight="1"/>
 98     <Button
 99         android:layout_width="wrap_content"
100         android:layout_height="wrap_content"
101         android:text="6"
102         android:id="@+id/bt6"
103         android:textSize="25sp"
104         android:layout_rowWeight="1"
105         android:layout_columnWeight="1"/>
106     <Button
107         android:layout_width="wrap_content"
108         android:layout_height="wrap_content"
109         android:text="+"
110         android:id="@+id/bt_add"
111         android:textSize="25sp"
112         android:layout_rowWeight="1"
113         android:layout_columnWeight="1"/>
114     <Button
115         android:layout_width="wrap_content"
116         android:layout_height="wrap_content"
117         android:text="1"
118         android:id="@+id/bt1"
119         android:textSize="25sp"
120         android:layout_rowWeight="1"
121         android:layout_columnWeight="1"/>
122     <Button
123         android:layout_width="wrap_content"
124         android:layout_height="wrap_content"
125         android:text="2"
126         android:id="@+id/bt2"
127         android:textSize="25sp"
128         android:layout_rowWeight="1"
129         android:layout_columnWeight="1"/>
130     <Button
131         android:layout_width="wrap_content"
132         android:layout_height="wrap_content"
133         android:text="3"
134         android:id="@+id/bt3"
135         android:textSize="25sp"
136         android:layout_rowWeight="1"
137         android:layout_columnWeight="1"/>
138     <Button
139         android:layout_width="wrap_content"
140         android:layout_height="wrap_content"
141         android:text="="
142         android:id="@+id/btdengyu"
143         android:textSize="25sp"
144         android:layout_columnWeight="1"
145         android:layout_rowSpan="2"
146         android:layout_rowWeight="1"
147         android:layout_gravity="fill"/>
148     <Button
149         android:layout_width="wrap_content"
150         android:layout_height="wrap_content"
151         android:text="0"
152         android:id="@+id/bt0"
153         android:textSize="25sp"
154         android:layout_columnWeight="1"
155         android:layout_rowWeight="1"/>
156
157     <Button
158         android:layout_width="wrap_content"
159         android:layout_height="wrap_content"
160         android:text="."
161         android:id="@+id/bt_dian"
162         android:textSize="25sp"
163         android:layout_rowWeight="1"
164         android:layout_columnWeight="1"/>
165     <Button
166         android:layout_width="wrap_content"
167         android:layout_height="wrap_content"
168         android:text="()"
169         android:id="@+id/bt_kuohao"
170         android:textSize="25sp"
171         android:layout_rowWeight="1"
172         android:layout_columnWeight="1"/>
173 </GridLayout>
时间: 2024-08-10 19:18:44

UI事件 计算器界面的相关文章

UI事件监听的击穿

什么是UI事件监听的击穿 在游戏视图中,有两个UI界面叠在一起的时候,单击一个空白处,却触发了被覆盖在下层了UI界面中的单击事件,这就是单击击穿了上层界面. 假设场景中放置了一个箱子,单击箱子会触发一个开箱事件,如果单击一个UI,恰好UI在视觉上将箱子覆盖了,那么它也许就会触发箱子的单击事件. 如何避免和解决UI事件监听的击穿 第一种方法:用一层BoxCollider覆盖,进行遮挡. 在界面底板上Attach一个BoxCollider. 第二种方法:使用EventMask Unity的Camer

从零开始学android&lt;使用嵌套布局实现计算器界面.十七.&gt;

所谓的嵌套布局就是在一个文件中嵌套多个布局文件 <span style="font-size:18px;"> <LinearLayout android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="vertical" > <FrameLayout android:layou

Qt 计算器界面实现

学习目的: QWidget  QPushbutton  QLineEdit使用. 通过Qt 代码实现一个计算器界面. QWidget窗口组件: QWidget类继承自 QObject 类和QPaintDevice类 QObject 是所有 支持Qt对象模型 的基类 QPaintDevice Qt中所有 可绘制组件 的基类 QWidget能够绘制自己 和处理 用户的输入 QWidget 是Qt所有窗口组件类的父类  QWidget 是所有窗口组件的抽象 Qt中的每个窗口组件都是一个QWidget

计算器界面——GridLayout

1 <?xml version="1.0" encoding="utf-8"?> 2 <GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 and

Android计算器界面

1 <?xml version="1.0" encoding="utf-8"?> 2 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 an

免费素材:25套免费的 Web UI 设计的界面元素(转)

Web 元素是任何网站相关项目都需要的,质量和良好设计的元素对于设计师来说就像宝贝一样.如果您正在为您的网站,博客,Web 应用程序或移动应用程序寻找完美设计的网页元素,那么下面这个列表会是你需要的. 今天这里收集的免费资源是25套免费的 Web UI 设计的界面元素,用于和Mobile App设计.它包括所有的设计元素的 PSD 格式,某些元素提供矢量格式,可以缩放到任意大小. UI Kit – Free PSD Download Ui Kit [Free PSD] Download Free

屏蔽UI事件

UGUI 提供了一个检测是否点击在UI上的方法 EventSystem.current.IsPointerOverGameObject(); 但是该方法在PC上检测正常,结果拿到Android真机测试上,永远检测不到. 在网上找了一些大神的解决方案 using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using UnityEngine.EventS

Android计算器界面布局

Android计算器界面图: 所定义的XML布局文件,主要用到的是TableLayout: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_heigh

JAVA开发简易计算器界面-SWT

大家好,我是成都[LD],博客四年前就申请了,一直没打理,最近正好有时间,遂萌生了写技术博客的念头.我不得不感慨现在新技术更新很快,一不小心,就感觉自身就Out了.记得一年前,当时我也是在51CTO上了解到NoSQL和Hadoop这样的信息,当时就简单觉得很新奇,没想到一年之后发展如此迅速~~当然我这样说,并不是叫大家去追寻新技术,最根本的还是基础打牢靠,休息的时候多去了解下最新的IT动态.学习下前辈高手的一些技能~~打铁还需自身硬嘛! 我写博客的目的:一来是为了促进自身的进步,二来是为了希望与