Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've had the same problem and created the following code to easily use different animations. It only supports translation and alpha levels for now as I haven't used scaling, but could easily be extended to support more features.</p> <p>I reset the scroll and the visibility before starting the animation, but that's just because I needed on/off animations. </p> <p>And the "doEnd" boolean is there to avoid a stack overflow on the recursion (scrollTo calls onAnimationEnd for some obscure reason...)</p> <pre><code>private void setViewPos(View view, Animation anim, long time){ // Get the transformation Transformation trans = new Transformation(); anim.getTransformation(time, trans); // Get the matrix values float[] values = new float[9]; Matrix m = trans.getMatrix(); m.getValues(values); // Get the position and apply the scroll final float x = values[Matrix.MTRANS_X]; final float y = values[Matrix.MTRANS_Y]; view.scrollTo(-(int)x, -(int)y); // Show/hide depending on final alpha level if (trans.getAlpha() &gt; 0.5){ view.setVisibility(VISIBLE); } else { view.setVisibility(INVISIBLE); } } private void applyAnimation(final View view, final Animation anim){ view.scrollTo(0, 0); view.setVisibility(VISIBLE); anim.setAnimationListener(new AnimationListener(){ private boolean doEnd = true; @Override public void onAnimationEnd(Animation animation) { if (doEnd){ doEnd = false; setViewPos(view, animation, anim.getStartTime() + anim.getDuration()); } } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { } }); view.startAnimation(anim); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload