The following is an animation that changes the color of the imageview when you press the button, but if you press this id=start button continuously, the animation will start again from the beginning (although it's only natural).
For example, when the same button is pressed continuously, the animation does not start from the beginning when the same button is used.In other words, we would like to give instructions such as ignoring the same signal.
The code is dirty and I'm sorry I didn't know, but if you know how to do it, I'd appreciate it if you could let me know.
Thank you for your cooperation.
setContentView(R.layout.activity_main);
image=(ImageView) findViewById (R.id.image);
btnStart=(Button) findViewById (R.id.start);
btnStart.setOnClickListener(newView.OnClickListener(){
@ Override
public void onClick (View v) {
startColorAnimation (image);
}});
btnStart=(Button) findViewById (R.id.start1);
btnStart.setOnClickListener(newView.OnClickListener(){
@ Override
public void onClick (View v) {
startColorAnimation1(image);
}});
or
public void startColorAnimation(View view){
int colorStart = 0xFFffff;
int colorEnd = 0xFF000000;
ValueAnimator colorAnim=ObjectAnimator.ofInt(
view, "backgroundColor", colorStart, colorEnd);
colorAnim.setDuration(2000);
colorAnim.setEvaluator(newArgbEvaluator());
colorAnim.setRepeatCount(100);
colorAnim.setRepeatMode(ValueAnimator.REVERSE);
colorAnim.start();
}
public void startColorAnimation1 (View view) {
int colorStart = 0xfff53b6d;
// int colorStart = view.getSolidColor();
int colorEnd = 0xFF000000;
ValueAnimator colorAnim=ObjectAnimator.ofInt(
view, "backgroundColor", colorStart, colorEnd);
colorAnim.setDuration(2000);
colorAnim.setEvaluator(newArgbEvaluator());
colorAnim.setRepeatCount(100);
colorAnim.setRepeatMode(ValueAnimator.REVERSE);
colorAnim.start();
}
Why don't you have ValueAnimator as a class field instead of as local to the method, and do nothing to get out of the method if the ValueAnimator object already exists?
public class MyActivity extensions Activity {
ValueAnimator anim;
protected void onCreate() {
super.onCreate()
setContentView(R.layout.activity_main);
Button btnStart=(Button) findViewById (R.id.start);
btnStart.setOnClickListener(newView.OnClickListener(){
@ Override
public void onClick (View v) {
startColorAnimation (image);
}
});
}
public void startColorAnimation (View view) {
// If the animation is already running, do nothing.
if(anim!=null)return;
int colorStart = 0xFFffff;
int colorEnd = 0xFF000000;
anim=ObjectAnimator.ofInt(view, "backgroundColor", colorStart, colorEnd);
anim.setDuration (2000);
anim.setEvaluator(newArgbEvaluator());
anim.setRepeatCount(100);
anim.setRepeatMode(ValueAnimator.REVERSE);
anim.start();
}
}
*Partial omitted
In addition, you can only run animation once as above, so you must do anim=null
somewhere to be able to run animation again.
918 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
621 Uncaught (inpromise) Error on Electron: An object could not be cloned
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
582 PHP ssh2_scp_send fails to send files as intended
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.