浏览代码

Button done

pull/1/head
highball-it 8 年前
父节点
当前提交
ef9b41fbfa
共有 3 个文件被更改,包括 86 次插入2 次删除
  1. +17
    -2
      app/src/main/java/de/mlte/soundboard/MainActivity.kt
  2. +44
    -0
      app/src/main/res/drawable/progress_bar_states.xml
  3. +25
    -0
      app/src/main/res/layout/activity_main.xml

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

@@ -1,12 +1,27 @@
package de.mlte.soundboard

import android.support.v7.app.AppCompatActivity
import android.animation.ObjectAnimator
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.ProgressBar
import android.widget.TextView

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val progressBar = findViewById<ProgressBar>(R.id.progress_bar)
val objectAnimator = ObjectAnimator.ofInt(progressBar, "progress", progressBar.getProgress(), 100).setDuration(2000)
val btn = findViewById<TextView>(R.id.text_view_button)

objectAnimator.addUpdateListener({ valueAnimator ->
val progress = valueAnimator.animatedValue as Int
progressBar.progress = progress
})

btn.setOnClickListener {
objectAnimator.start()
}
}
}

+ 44
- 0
app/src/main/res/drawable/progress_bar_states.xml 查看文件

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
<shape>
<gradient
android:startColor="#777777"
android:centerColor="#333333"
android:centerY="0.75"
android:endColor="#222222"
android:angle="270"
/>
</shape>
</item>

<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<gradient
android:startColor="#234"
android:centerColor="#234"
android:centerY="0.75"
android:endColor="#a24"
android:angle="270"
/>
</shape>
</clip>
</item>

<item android:id="@android:id/progress">
<clip>
<shape>
<gradient
android:startColor="#999999"
android:centerColor="#777777"
android:centerY="0.75"
android:endColor="#555555"
android:angle="270"
/>
</shape>
</clip>
</item>

</layer-list>

+ 25
- 0
app/src/main/res/layout/activity_main.xml 查看文件

@@ -15,4 +15,29 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indeterminate="false"
android:progressDrawable="@drawable/progress_bar_states" />

<TextView
android:id="@+id/text_view_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="6dp"
android:text="Enter"
android:textColor="@android:color/white"
android:textSize="16sp"
android:textStyle="bold" />

</FrameLayout>

</android.support.constraint.ConstraintLayout>

正在加载...
取消
保存