浏览代码

Moved button to own class

pull/1/head
Nils 8 年前
父节点
当前提交
f090724c85
共有 3 个文件被更改,包括 23 次插入14 次删除
  1. +2
    -12
      app/src/main/java/de/mlte/soundboard/MainActivity.kt
  2. +19
    -0
      app/src/main/java/de/mlte/soundboard/SoundButton.kt
  3. +2
    -2
      app/src/main/res/layout/layout_button.xml

+ 2
- 12
app/src/main/java/de/mlte/soundboard/MainActivity.kt 查看文件

@@ -88,18 +88,8 @@ class MainActivity : AppCompatActivity() {

for (row in 0..1) {
for (col in 0..1) {
val newFrame = inflater.inflate(R.layout.layout_button, null)
// newFrame.findViewById<ProgressBar>(R.id.progress_bar)
// newFrame.findViewById<TextView>(R.id.text_view_button)

val params = GridLayout.LayoutParams()
params.columnSpec = GridLayout.spec(col, 1, 1.0f)
params.rowSpec = GridLayout.spec(row, 1, 1.0f)
params.width = 0
params.height = 0
newFrame.layoutParams = params

parent.addView(newFrame)
val soundButton = SoundButton(this, col, row)
parent.addView(soundButton)
}
}
}


+ 19
- 0
app/src/main/java/de/mlte/soundboard/SoundButton.kt 查看文件

@@ -0,0 +1,19 @@
package de.mlte.soundboard

import android.content.Context
import android.view.View
import android.widget.FrameLayout
import android.widget.GridLayout

class SoundButton : FrameLayout {
constructor(context: Context, col: Int, row: Int) : super(context) {
View.inflate(context, R.layout.layout_button, this)

val params = GridLayout.LayoutParams()
params.columnSpec = GridLayout.spec(col, 1, 1.0f)
params.rowSpec = GridLayout.spec(row, 1, 1.0f)
params.width = 0
params.height = 0
layoutParams = params
}
}

+ 2
- 2
app/src/main/res/layout/layout_button.xml 查看文件

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp">
<ProgressBar
android:id="@+id/progress_bar"


正在加载...
取消
保存