B
B
blare2013-02-25 19:05:19
Android
blare, 2013-02-25 19:05:19

setAnimation + setVisibility not working on Android 4?

Animation animation= AnimationUtils.loadAnimation(this, R.anim.bottom_in);
animation.setDuration(200);
buttonsBar.setAnimation(animation);
buttonsBar.setVisibility(View.VISIBLE);

R.anim.bottom_in:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
            android:duration="300"
            android:fromYDelta="100%p"
            android:toYDelta="0%p" />
</set>

buttonsBar is a RelativeLayout, initially it has android:visibility="gone"
As a result, in android version 2 the bar is shown, on android version 4 it is not, but if you tap on the place where it is located, the bar will seem as if it is not rendered during animation.
During the animation of hiding the bar, and it is similar, the bar is hidden, previously, if it was invisible due to this incomprehensible situation, having appeared.
Tell me how to be?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
palmut, 2013-02-25
@palmut

Maybe it's worth setting Animation.AnimationListener in animation and moving buttonsBar.setVisibility(View.VISIBLE); in onAnimationEnd?

V
Vladimir Yakushev, 2013-02-25
@VYakushev

Judging by the animation XML file, you are changing the Y-axis size from 100% to 0% with respect to the parent buttonsBar. That is, in the animation you hide the buttonsBar, and in the properties you set the visibility. Here it seems to be visible to you, but hidden by animation.

A
Alexander Bloch, 2014-03-03
@alexblokh

Good afternoon!
Try like this:

buttonsBar.setVisibility(View.VISIBLE);
buttonsBar.startAnimation(this,AnimationUtils.loadAnimation(R.anim.bottom_in));

setAnimation - sets the animation for the given View. Better use the .startAnimation(Context context,Animation anim); method to start the animation.
If you need to start an infinite animation and then stop it, for example for a loading animation, then:
if(needAnimate)
 view.startAnimation(context,AnimationUtils.loadAnimation(R.anim.download_animation));
else
 view.clearAnimation();

For the future:
<rotate
        android:fillAfter="true"
        android:fromDegrees="0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:pivotX="0.5"
        android:pivotY="0.5"
        android:toDegrees="180" />

100%p - means that the animation will be relative to the parent, i.e. ViewParent. If you want to animate relative to this View, then write 100%.
fillAfter - will leave the View in its final position after the animation is completed. In the example - a rotation of 180 degrees.
interpolator is a mathematical function that breaks your animation into intervals. At these intervals, your animation runs at different speeds. decelerate_interpolator will allow your bar to move onto the screen more naturally, slowing it down.
The @android:anim package provides a basic set of interpolators. If I'm not mistaken, acelerete_decelerate interpolation is applied to the animation by default.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question