I need to implement a moving/scrolling textview that got a clickable span. I also need to make the animation look like those banner ads below the news that repeat and repeat endlessly. I used TranslateAnimation before for a tv app and able to have it work because what I get is the keyEvent and the the touch. I need to implement it now on a tablet app which doesn't have any external input source other than the touchscreen itself.
I tried to use TranslateAnimation again for the tablet app but it doesn't work. Upon searching about the different animation I could use, I've learned that TranslateAnimation just animates the look of the view and the the whole view itself. It doesn't move the clickable parts with the look so I looked for a different one.
Then I stumbled upon PropertyAnimator. It's what I clearly need for my problem. But there's also a drawback to it. It doesn't support repeating.
What I currently have is this code below.
lbl.animate();
lbl.animate().x(-lblWidth).y(0);
lbl.animate().setDuration(animDuration);
lbl.animate().setInterpolator(new LinearInterpolator());
lbl.animate().setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
lbl.animate();
lbl.animate().x(lblWidth).y(0);
lbl.animate().setDuration(0);
lbl.animate().x(-lblWidth).y(0);
lbl.animate().setDuration(animDuration);
lbl.animate().setInterpolator(new LinearInterpolator());
lbl.animate().setListener(this);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
After the first run, the animation ends. It repeats because it prints my log but it's not showing on screen.
I was trying to make a repeating effect with that code. I was trying to recreate something like this code below.
transAnim = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_PARENT, 1.0f,
TranslateAnimation.RELATIVE_TO_SELF, -1.0f,
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.ABSOLUTE, 0f
);
transAnim.setRepeatCount(-1);
transAnim.setRepeatMode(Animation.RESTART);
transAnim.setInterpolator(new LinearInterpolator());
transAnim.setDuration(animDuration);
transAnim.setFillAfter(true);
What the code above does is from the right, outside the screen, I start an animation that goes to the left, outside the screen. Then, if the view's end reach the left, outside the screen, tell the animation to restart from the beginning.
I made it work now by adding a single short line of code above everything.
lbl.setX(screenWidth);
lbl.animate().x(-lblWidth).y(0);
lbl.animate().setDuration(animDuration);
lbl.animate().setInterpolator(new LinearInterpolator());
Then using those line of code again on the onAnimationEnd of the animate listener. Now I thought of another thing, can I pause this animation? Because I found a way to do it for TranslateAnimation. Is there a hack way to do it?
Try this I hope it work for you.