i use this code to when i click on a imagebox, run an animation on another object and dissaper itself via visibility.GONE. but it doesnt work!! here is my code:
againbtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//answer button on animation
Animation anim2 = AnimationUtils.loadAnimation(MainActivity.this, R.anim.askbtnonanim);
anim2.setFillAfter(true);
askbtn.startAnimation(anim2);
//gone myselft (againbtn)
againbtn.setVisibility(View.GONE);
}
});
if a delete 3 animation line from this code, everything is OK and works, but now it doesn't. but why? it's related to anim2.setFillAfter(true); ??? i put this because my animation run one time and dont reset! please help me
Try this
You have to clear the view animation then you can setVisibility
animation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {}
#Override
public void onAnimationEnd(Animation animation) {
view.clearAnimation();
view.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {}
});
You should implement Animation Listener and in onAnimationEnd() you should perform your task... hope below code will help you...
anim2.setAnimationListener(new Animation.AnimationListener(){
#Override
public void onAnimationStart(Animation arg0) {
}
#Override
public void onAnimationRepeat(Animation arg0) {
}
#Override
public void onAnimationEnd(Animation arg0) {
againbtn.setVisibility(View.GONE); //set your button visibility here
}
});
I think put visibility button before animation coding the this might work
againbtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//gone myselft (againbtn)
againbtn.setVisibility(View.GONE);
//answer button on animation
Animation anim2 = AnimationUtils.loadAnimation(MainActivity.this, R.anim.askbtnonanim);
anim2.setFillAfter(true);
askbtn.startAnimation(anim2);
}
});
Calling clearAnimation() on the view that is doing the animation before calling View.INVISIBLE, or GONE does the trick.
use AnimationListener for setting Button Visibility GONE when Animation end.
.....
anim2.setAnimationListener(animButnListener);
askbtn.startAnimation(anim2);
AnimationListener animButnListener = new AnimationListener(){
#Override
public void onAnimationEnd(Animation animation) {
// make Button Visibility GONE here
againbtn.setVisibility(View.GONE);
}
//.......other AnimationListener methods
};
Related
I created new custom Button class, I want to achieve, whenever user go to any activity my generic button want to expand from circle to default width. While expanding I want to hide button text for while until button animation complete.
Please check my below code:
private void animateMe(Context context){
final String btnText = this.getText().toString();
final FIButton fiButton = this;
fiButton.setText("");
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
fiButton.setText(btnText);
}
},500);
Animation animation = AnimationUtils.loadAnimation(context,
R.anim.expand);
super.startAnimation(animation);
}
Easily by
ViewCompat.animate(fiButton ).setStartDelay(500).alpha(1).setDuration(700).setInterpolator(new DecelerateInterpolator(1.2f)).start();
note that you have to set the fiButton alpha to zero android:alpha="0.0"
in you xml or on create view
this line will animate your view from 0 to 1 in 700 millisecond after 500 millisecond.
You can use an AnimationListener. On finishing the animation you should do setText on the TextView.
private void animateMe(Context context){
final String btnText = this.getText().toString();
final FIButton fiButton = this;
fiButton.setText("");
Animation animation = AnimationUtils.loadAnimation(context, R.anim.expand);
animation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
fiButton.setText("");
}
#Override
public void onAnimationEnd(Animation animation) {
fiButton.setText(btnText);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
super.startAnimation(animation);
}
I want the Layout"authentification" to appear after the Splash screen, in my application it's appear by default please some one help me!!!!!
pleaaase i need help
public class Splash extends Activity {
LinearLayout ln;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashh);
ln = (LinearLayout) findViewById(R.id.LinLaySpalScrenLogin);
final ImageView iv = (ImageView) findViewById(R.id.imageView);
final Animation an = AnimationUtils.loadAnimation(getBaseContext(),R.anim.rotate);
final Animation an2 = AnimationUtils.loadAnimation(getBaseContext(),R.anim.abc_fade_out);
iv.startAnimation(an);
an.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
iv.startAnimation(an2);
finish();
ln.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
}
}
You can set android:visibility="gone" in your LinearLayout xml file that contains your Splash Screen and then call yourlayout.setVisibility(View.VISIBLE); after you finish your animation.
Also your activity will end as soon as your animation finishes since you have called finish() before ln.setVisibility(View.VISIBLE); Try to remove finish() and only call it on some event such as Button click or something like that
You have ln.setVisibility(View.VISIBLE); after finish();. Try changing to :-
ln.setVisibility(View.VISIBLE);
finish();
However, this will probably not work as because as soon as the make the layout visible. The activity would finish. You probably want to display the authentication in another activity after the splash has completed.
I want to disable click on button when the animation running.
the code is below:
AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(4000);
anim.setRepeatMode(Animation.REVERSE);
btnTag.startAnimation(anim);
So i want to cant click the button until animation done.
I normally accomplish something like this is using an AnimationListener. It allows you to run code at various stages of the animation.
This code is untested, but the way it should look is:
AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(4000);
anim.setRepeatMode(Animation.REVERSE);
anim.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
btnTag.setClickable(false);
}
#Override
public void onAnimationEnd(Animation animation) {
btnTag.setClickable(true);
}
#Override
public void onAnimationRepeat(Animation animation) {}
});
btnTag.startAnimation(anim);
Not sure if btnTag is your button or a view holding your button, but call the button's setClickable(boolean clickable) method to enable and disable the button.
I would like to share the solution I found for this problem, for those who use data-binding:
binding.ivImage.setOnClickListener {
binding.ivImage.animate().apply {
duration=1000
scaleXBy(.5f)
scaleYBy(.5f)
rotationYBy(360f)
translationYBy(200f)
}.withEndAction {
binding.ivImage.animate().apply {
duration = 1000
scaleXBy(-.5f)
scaleYBy(-.5f)
rotationXBy(360f)
translationYBy(-200f)
}
}
}
binding.ivImage.animate().setListener(object: Animator.AnimatorListener{
override fun onAnimationStart(p0: Animator?) {
binding.ivImage.isClickable=false
binding.ivImage.isEnabled=false
}
override fun onAnimationEnd(p0: Animator?) {
binding.ivImage.isClickable=true
binding.ivImage.isEnabled=true
}
override fun onAnimationCancel(p0: Animator?) {
binding.ivImage.isClickable=true
binding.ivImage.isEnabled=true
}
override fun onAnimationRepeat(p0: Animator?) {
TODO("Not yet implemented")
}
})
I have ImageView that I want to animate it whenever user clicks on it.
So I ended up with this simple solution:
public void onClick(View v) {
imageView.animate()
.rotationX(360).rotationY(360)
.setDuration(1000)
.setInterpolator(new LinearInterpolator());
}
It works just perfect, but only FIRST TIME (first click plays animation, after that animation does not work at all).
How can I fix that?
You need to reset the rotation before or after each animation. For example:
imageView.animate()
.rotationX(360).rotationY(360)
.setDuration(1000)
.setInterpolator(new LinearInterpolator())
.setListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animator) {
imageView.setRotationX(0);
imageView.setRotationY(0);
}
});
these are just the methods i can override during animationListener.
http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html
Animation animation
animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.device_box);
animation.setAnimationListener(new AnimationListener(){
#Overridepublic void onAnimationEnd(Animation arg0) {}
#Override public void onAnimationRepeat(Animation animation) {}
#Override public void onAnimationStart(Animation animation) {}});
I think adding a thread in onAnimationStart and stop it on onAnimationEnd and getting the coordinates with a loop inside the thread, this may work.
But i think that i could get some problems with buttons because, when animating them in this way, only the background moves, not button area itself
In this case, i have to investigate more with buttons
What do you think about this, is there another way to achieve what i want?
Is this the better way to do it ?
I researched, and what I got is this, not X and Y but can handle the data as get what has been animated as time.
ObjectAnimator anim = ObjectAnimator.ofFloat(box_image, "translationX", 0 , cant);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator arg0) {
double f = Math.round(arg0.getAnimatedFraction()*1000.0)/1000.0;
Log.d("datos", ""+f);
}
});
anim.setDuration(1000);
anim.start();