效果

配置

apply plugin: 'kotlin-android-extensions'

代码

package com.kok.formoneyimport android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.appcompat.widget.AppCompatButton
import kotlinx.android.synthetic.main.activity_main.*
import java.lang.Exception
import java.text.DecimalFormatclass MainActivity : AppCompatActivity() {var handleType = false; // true 表示高价值币种var type01 = 0;var type02 = 1;override fun onCreate(savedInstanceState: Bundle?) {window.statusBarColor = Color.parseColor("#528A63")super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)initView()}fun initView() {addItem()radioGroup_type.setOnCheckedChangeListener(checkChangeListener)radioGroup_type02.setOnCheckedChangeListener(checkChangeListener)button_add.setOnClickListener(onClickListener)button_count.setOnClickListener(onClickListener)}fun addItem() {var itenLayout = LinearLayout(this)var params = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)itenLayout.layoutParams = paramsitenLayout.orientation = LinearLayout.HORIZONTALvar hite = TextView(this)params = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT)hite.layoutParams = paramshite.text = "交换汇率:"itenLayout.addView(hite)var inputView = EditText(this)params = ViewGroup.LayoutParams(200,ViewGroup.LayoutParams.WRAP_CONTENT)inputView.layoutParams = paramsitenLayout.addView(inputView)var resultView = TextView(this)var linearLayoutParams = LinearLayout.LayoutParams(0,ViewGroup.LayoutParams.WRAP_CONTENT)linearLayoutParams.weight = 1fresultView.layoutParams = linearLayoutParamsitenLayout.addView(resultView)var closeButtom = ImageButton(this)linearLayoutParams = LinearLayout.LayoutParams(40, 40)linearLayoutParams.gravity = Gravity.CENTERlinearLayoutParams.marginEnd = 40closeButtom.layoutParams = linearLayoutParamscloseButtom.background  = resources.getDrawable(R.mipmap.close,null)closeButtom.setOnClickListener {linearLayout_translate_contant.removeView(itenLayout)}itenLayout.addView(closeButtom)linearLayout_translate_contant.addView(itenLayout)}fun count() {var amount: Float? = nullvar rate: Float? = nulltry {amount = edittext_mony_amount.text.toString().toFloat()rate = edittext_mony_rate.text.toString().toFloat()} catch (e: Exception) {amount = nullrate = null}//for (index in 0 until linearLayout_translate_contant.childCount) {var itemLayout: LinearLayout =linearLayout_translate_contant.getChildAt(index) as LinearLayoutvar inputView: EditText = itemLayout.getChildAt(1) as EditTextvar resultView: TextView = itemLayout.getChildAt(2) as TextViewtry {if (amount == null || rate == null) {resultView.text = "持有数据解析失败"} else {var inputRate = inputView.text.toString().toFloat()var result = 0fif(handleType){result = amount*inputRate -  amount*rate}else{result = amount/inputRate -  amount/rate}var name = when(type02){0 ->{"Piso"}1->{"Yuan"}2->{"Dollar"}else -> "null"}if(result>0){resultView.text = "盈:${DecimalFormat("#.00").format(Math.abs(result))}"+nameresultView.setTextColor(Color.RED)}else if(result<0){resultView.text = "亏:${DecimalFormat("#.00").format(Math.abs(result))}"+nameresultView.setTextColor(Color.GREEN)}else{resultView.text = "持平"resultView.setTextColor(Color.BLACK)}}} catch (e: Exception) {resultView.text = "交换数据解析失败"}}}fun refreshType(){if(type01>type02){handleType = true}else{handleType = false}}var checkChangeListener =object: RadioGroup.OnCheckedChangeListener{override fun onCheckedChanged(group: RadioGroup?, checkedId: Int) {when(checkedId){R.id.radioButton_type_01 ->{type01 = 0}R.id.radioButton_type_02 ->{type01 = 1}R.id.radioButton_type_03 ->{type01 = 2}R.id.radioButton_type_011 ->{type02 = 0}R.id.radioButton_type_022 ->{type02 = 1}R.id.radioButton_type_033 ->{type02 = 2}}refreshType()}}var onClickListener = object : View.OnClickListener {override fun onClick(v: View?) {when (v) {button_add -> {addItem()}button_count -> {count()}}}}}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"android:orientation="vertical"><ScrollViewandroid:layout_width="match_parent"android:layout_height="wrap_content"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="持有币种"></TextView><RadioGroupandroid:id="@+id/radioGroup_type"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><RadioButtonandroid:id="@+id/radioButton_type_01"android:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"android:text="Piso"android:checked="true"></RadioButton><RadioButtonandroid:id="@+id/radioButton_type_02"android:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"android:text="Yuan"></RadioButton><RadioButtonandroid:id="@+id/radioButton_type_03"android:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"android:text="Dollar"></RadioButton></RadioGroup><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="交换币种"></TextView><RadioGroupandroid:id="@+id/radioGroup_type02"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><RadioButtonandroid:id="@+id/radioButton_type_011"android:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"android:text="Piso"></RadioButton><RadioButtonandroid:id="@+id/radioButton_type_022"android:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"android:text="Yuan"android:checked="true"></RadioButton><RadioButtonandroid:id="@+id/radioButton_type_033"android:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"android:text="Dollar"></RadioButton></RadioGroup><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="持有数量"></TextView><EditTextandroid:id="@+id/edittext_mony_amount"android:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"></EditText><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="持有汇率"></TextView><EditTextandroid:id="@+id/edittext_mony_rate"android:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"></EditText></LinearLayout><LinearLayoutandroid:id="@+id/linearLayout_translate_contant"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"></LinearLayout><androidx.appcompat.widget.AppCompatButtonandroid:id="@+id/button_add"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="添加交换汇率"></androidx.appcompat.widget.AppCompatButton><androidx.appcompat.widget.AppCompatButtonandroid:id="@+id/button_count"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="计算换汇"></androidx.appcompat.widget.AppCompatButton></LinearLayout></ScrollView></LinearLayout>

Android 汇率换算对比小工具相关推荐

  1. android上调试H5小工具

    由于android上,部分网页报错,网页直接调试是看不到的或者显示不够具体,此app方便H5开发人员,查看具体错误打印.并未做到分步调试. 而部分类似格式错误,IOS上,由于本身的严谨性可能会反而不报 ...

  2. mysql 表结构差异对比小工具

    项目场景: 在进行慢sql评审时,发现测试环境增加了索引生产并没有.然后有些表字段长度也不一样,坑大发了.决定写一个小工具对比一下测试跟生产表结构差异,大致思路连接数据库获取建表语句进行对比,忽略主键 ...

  3. android AppWidgetProvider开发桌面小工具

    什么是桌面小工具  就是你写好代码后 双指缩放桌面屏幕(三星手机出现小组件,华为出现窗口小工具)点击之后会出现你继承AppWidgetProvider所编写的界面 效果: 代码: /** * Impl ...

  4. android 开发小工具,Android 开发者必备的八款小工具

    在做Android 开发过程中,会遇到一些小的问题,虽然自己动手也能解决,但是有了一些小工具,解决这些问题就得心应手了,今天就为大家推荐一些Android 开发必备的小工具. Android Pixe ...

  5. 这些小工具让你的Android 开发更高效

    在做Android 开发过程中,会遇到一些小的问题,虽然自己动手也能解决,但是有了一些小工具,解决这些问题就得心应手了,今天就为大家推荐一下Android 开发遇到的小工具,来让你的开发更高效. Vy ...

  6. android倒计时小工具,为五一放假倒计时《倒数日小工具》

    俗话说好记性不如烂笔头,有时候记到脑子里并不一定是最保险,因为它总有短路和不灵光的时候,当你忘记精彩的球赛.周年纪念日.生日等重要时刻的时候,再拍着脑袋追悔莫及就为时已晚了.装上这款Android&l ...

  7. ADI射频电路计算小工具ADIsimRF介绍

    做射频收发组件的同志都知道,设计一个模块的工作量之大,而且各种计算相当繁琐,每一个链路当中有各种指标需要设计阶段即满足指标而且留有余量.这就要求设计人员有相当的水平和资历了,所以很多大的项目都是些资深 ...

  8. Android 开发小工具之:Custom Tabs

    上周 Android Support 库偷偷摸摸更新了,里面多了几个小工具.今天来看看其中之一: Custom Tabs . 注意这个指的是 Chrome 浏览器的自定义多窗口 的意思而不是指 And ...

  9. android小工具-系统音量管理器

    简介:调节系统音量的小工具,能够快捷的调节系统铃声,媒体音乐.闹钟和通话声音.你可能会想,手机自带的音量键还不够快捷吗?还得写个程序?首先,用音量键调音只能调节一种声音,像闹钟这种声音不能直接调.其次 ...

  10. Flutter桌面小工具 -- 灵动岛【Windows+Android版本】

    通过此篇文章,你将了解到: Flutter动画实现灵动岛: Flutter如何开发一个置顶可自由拖拽的小工具: 分享一些关于灵动岛的想法. ⚠️本文为稀土掘金技术社区首发签约文章,14天内禁止转载,1 ...

最新文章

  1. OpenCV扫描图像,查找表和时间测量
  2. 为什么说Swift正在颠覆整个互联网生态?
  3. 同一个工作组无法查看计算机,win7系统在同一个工作组看不到其他电脑的解决方法...
  4. 工业以太网交换机的重要技术参数分析
  5. 《Java8实战》笔记(01):为什么要关心Java8
  6. Git学习笔记与IntelliJ IDEA整合
  7. 单片机百位计数c语言,单片机c语言版数管动态显示实验报告.doc
  8. 关于XP系统远程桌面的一点点记录
  9. 上位机和下位机有什么区别和关系?常用上位机软件开发工具介绍
  10. x509证书、openssl、go生成证书
  11. AUTOCAD——矩形命令
  12. 赋值,浅拷贝,深拷贝区别和实现方法
  13. 蚂蚁金服CTO程立:创新发展数字时代金融关键技术
  14. perl代码实现DNA翻译蛋白序列
  15. SQL中类型转换函数
  16. thinkPHP生成微信支付平台证书
  17. 【架构分析】Weston Inside - 基础数据结构详解
  18. 视频教程-三维游戏引擎开发-图形理论基础-其他
  19. 江湖2 java_热血江湖2手游一键端源码搭建教程+APP端+WEB端+GM工具
  20. Python3 调用谷歌翻译

热门文章

  1. 中国大学计算机专业排名教育部,中国校友会网2018中国大学计算机类各本科专业排行榜...
  2. win10虚拟内存设置方法
  3. WINDOWS虚拟内存设置
  4. 高三数学辅导:不等式、推理与证明
  5. HTTP:实时消息推送
  6. 2019年 年终总结
  7. Windows下生成ssh密钥,并用ssh免密访问Linux服务器
  8. word文档中如何将软回车替换为硬回车
  9. python二元函数图像在线绘制_Python之Numpy:二元函数绘制/三维数据可视化/3D
  10. 画二元函数即三维图像的函数及matlab代码