Image is getting invisible with animation correctly but not getting visible again after clicking on the button.
public void jerry(View view) {
Button button = (Button) findViewById(R.id.button);
ImageView sjt = (ImageView) findViewById(R.id.imageView2);
if(sjt.getVisibility() == View.VISIBLE) {
sjt.setVisibility(View.GONE);
sjt.animate().alpha(0).rotationBy(1800).setDuration(3000);
} else {
sjt.setVisibility(View.VISIBLE);
sjt.animate().alpha(1).rotationBy(1800).setDuration(3000);
}
}
please use this code where btn is Button Object, you can get both animation perfectly by this code, if you are going with Visibility==GONE or something then it will Disappear your ImageView instantly when you call GONE .
int i= 0;
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
i=i+1;
if (i%2==1) {
sjt.animate().alpha(0).rotationBy(1800).setDuration(3000);
}
else {
sjt.animate().alpha(1).rotationBy(1800).setDuration(3000);
}
}
});
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(sjt.getVisibility() == View.VISIBLE) {
sjt.setVisibility(View.GONE);
sjt.animate().alpha(0).rotationBy(1800).setDuration(3000);
} else {
sjt.setVisibility(View.VISIBLE);
sjt.animate().alpha(1).rotationBy(1800).setDuration(3000);
}
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.