My target is to animate current view from it's current position(center), to top border of it's parent. Is that possible? I have already tried next code, but the problem is that my view disappears after animation:
Animation bottomUp = AnimationUtils.loadAnimation(context, R.anim.bottom_up);
popup.startAnimation(bottomUp);
and
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="100%"
android:toYDelta="0%"
android:fillAfter="true"
android:duration="500"/>
</set>
That can easily be done in Java with ViewPropertyAnimator
popup.animate().translationY(0).setDuration(500); // 0 is top of Y axis
The animation always starts at the current position.
Check the ViewPropertyAnimator docs for future animations, it's very easy to use and can save you a lot of code.
Related
This is the code I am using but the behaviour of the marquee is that is scrolls. How to make it to alternate i.e. it moves from right to left and then left to right.
public void setMarquee(TextView textView) {
textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
textView.setMarqueeRepeatLimit(-1);
textView.setHorizontallyScrolling(true);
textView.setSelected(true);
textView.requestFocus();
}
Step1
create folder called anim in res directory
step 2
create slide_left.xml
slide_left.xml
<translate
android:duration="3000"
android:fromXDelta="100%"
android:toXDelta="0" />
</set>
step 3
in main_activity.class
LinearLayout mlayout =
(LinearLayout)findViewById(R.id.mlayout); // the view u want to animate
Animation slide_left_anim;
slide_left_anim=
AnimationUtils.loadAnimation(getActivity().getApplicationContext(),
R.anim.slide_left);
slide_left_anim.setRepeatCount(Animation.INFINITE);
mlayout.startAnimation(slide_left_anim);
i have a transition animation xml
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="100%p"
android:toXDelta="0%p"
android:duration="400"/>
</set>
I want to apply this animation on several items but with varying duration. I'm trying to dynamically change duration by calling setDuration and then calling startAnimation.
mSlideLeft.setDuration(400);
view1.startAnimation(mSlideLeft);
mSlideLeft.setDuration(500);
view2.startAnimation(mSlideLeft);
mSlideLeft.setDuration(600);
view3.startAnimation(mSlideLeft);
but all view animation in same duration. How do I dynamically change duration of animation?
You're using the same Animation object for all three Views. So you're calling setDuration on the same object 3 times.
You need to create three separate Animation objects if you want to use three different durations.
Animation firstSlideLeft = AnimationUtils.loadAnimation(context, R.anim.slide_left);
firstSlideLeft.setDuration(400);
view1.startAnimation(firstSlideLeft);
Animation secondSlideLeft = AnimationUtils.loadAnimation(context, R.anim.slide_left);
secondSlideLeft.setDuration(500);
view2.startAnimation(secondSlideLeft);
Animation thirdSlideLeft = AnimationUtils.loadAnimation(context, R.anim.slide_left);
thirdSlideLeft.setDuration(600);
view3.startAnimation(thirdSlideLeft);
I have a view that I'm animating with the following animation:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:duration="1000"/>
</set>
I'm wondering if it's possible to put multiple operations in this set block so that I can have a different type of animation happen before the alpha one. Thanks!
That's precisely what the animation set is for:
Represents a group of Animations that should be played together. The
transformation of each individual animation are composed together into
a single transform. If AnimationSet sets any properties that its
children also set (for example, duration or fillBefore), the values of
AnimationSet override the child values.
You can include different animations in the set and control when they happen with their start time and duration.
I'm getting this weird issue. Basically I'm animating a view with translate animation. (Translate into the screen and out via 2 different events) My code for translate animation is:
final Animation animtopOut = new TranslateAnimation(0, 0, 0, -mainHeaderlayout.getMeasuredHeight());
animtopOut.setDuration(500);
animtopOut.setFillAfter(true);
mainHeaderlayout.setAnimation(animtopOut);
And the xml code is:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="#android:anim/accelerate_interpolator" >
<translate
android:fromYDelta="0%p"
android:toYDelta="-99%p"
android:duration="600"
android:fillAfter="true">
</translate>
</set>
Setting it using the code:
final Animation animtopOut = AnimationUtils.loadAnimation(mContext, R.anim.header_animate_out);
When I trigger the animation it works fine if I use the xml animation properties. The problem is when i use it via code. Which is what I want. It runs with translate animation only for the first time. The second time, when it is triggered, the view is inside the screen without animation. Please some one help me if I'm missing any properties. Thanks.
EDIT : (extra info)
There are actually two different animations that are triggered on the same view via two different events. I have actually posted one animation property. The other is almost the same. with just values are different.
Have you tried animation configuration like this
animtopOut.setRepeatCount(Animation.INFINITE);
animtopOut.setRepeatMode(Animation.RESTART);
animtopOut.setInterpolator(new LinearInterpolator());
?
I search but cant find out any infromation how to freeze last state of animation like rotation or else.
I think than animation it's change some pictures with show's last state.
I have next xml animation file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true">
<rotate android:fromDegrees="0" android:toDegrees="300"
android:duration="5000" android:pivotX="50%" android:pivotY="50%"
android:startOffset="10"
>
</rotate>
</set>
As you can see parameter toDegress it's setted to 300.
I use this animation xml to rotate text with next code
Animation animation1 = AnimationUtils.loadAnimation(this,
R.anim.myanimation);
animation1.setAnimationListener(this);
View animatedView1 = findViewById(R.id.rotatetext);
animatedView1.startAnimation(animation1);
But then animation stops text not rotated state no 300 degrees, it's returns to 0 degress.
How i can do what animation freeze on last frame?
Keep It Simple Stupid
Read,read and read documentation
When set to true, the animation transformation is applied after the
animation is over. The default value is false. If fillEnabled is not
set to true and the animation is not set on a View, fillAfter is
assumed to be true.
Must be a boolean value, either "true" or "false".
You can implement an AnimationListener and set to your animation object. write some code to change the View's state in the method onAnimationEnd().