效果
配置
apply plugin: 'kotlin-android-extensions'
代码
package com.kok.formoney
import 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.DecimalFormat
class 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 = params
itenLayout.orientation = LinearLayout.HORIZONTAL
var hite = TextView(this)
params = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
hite.layoutParams = params
hite.text = "交换汇率:"
itenLayout.addView(hite)
var inputView = EditText(this)
params = ViewGroup.LayoutParams(
200,
ViewGroup.LayoutParams.WRAP_CONTENT
)
inputView.layoutParams = params
itenLayout.addView(inputView)
var resultView = TextView(this)
var linearLayoutParams = LinearLayout.LayoutParams(
0,
ViewGroup.LayoutParams.WRAP_CONTENT
)
linearLayoutParams.weight = 1f
resultView.layoutParams = linearLayoutParams
itenLayout.addView(resultView)
var closeButtom = ImageButton(this)
linearLayoutParams = LinearLayout.LayoutParams(40, 40)
linearLayoutParams.gravity = Gravity.CENTER
linearLayoutParams.marginEnd = 40
closeButtom.layoutParams = linearLayoutParams
closeButtom.background = resources.getDrawable(R.mipmap.close,null)
closeButtom.setOnClickListener {
linearLayout_translate_contant.removeView(itenLayout)
}
itenLayout.addView(closeButtom)