-
Notifications
You must be signed in to change notification settings - Fork 2
/
Practice06Duration.java
74 lines (58 loc) · 2.3 KB
/
Practice06Duration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.geekholt.practiceui.view.lesson5;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.geekholt.practiceui.R;
public class Practice06Duration extends LinearLayout {
SeekBar durationSb;
TextView durationValueTv;
Button animateBt;
ImageView imageView;
int duration = 300;
public Practice06Duration(Context context) {
super(context);
}
public Practice06Duration(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public Practice06Duration(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
durationSb = (SeekBar) findViewById(R.id.durationSb);
durationValueTv = (TextView) findViewById(R.id.durationValueTv);
durationValueTv.setText(getContext().getString(R.string.ms_with_value, duration));
durationSb.setMax(10);
durationSb.setProgress(1);
durationSb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
duration = progress * 300;
durationValueTv.setText(getContext().getString(R.string.ms_with_value, duration));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
animateBt = (Button) findViewById(R.id.animateBt);
imageView = (ImageView) findViewById(R.id.imageView);
animateBt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO 在这里处理点击事件,执行动画。记得使用 `setDuration(duration)` 来设置动画的时长。
imageView.animate().setDuration(duration).rotationX(360f);
}
});
}
}