Apply Horizontal Scroll Animation - Android Animation

Android examples for Animation:Animation Creation

Description

Apply Horizontal Scroll Animation

Demo Code

// Copyright 2009-2011 Google, All Rights reserved
//package com.java2s;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;

public class Main {
    private static void ApplyHorizontalScrollAnimation(View view,
            boolean left, int speed) {
        float sign = left ? 1f : -1f;
        AnimationSet animationSet = new AnimationSet(true);
        animationSet.setRepeatCount(Animation.INFINITE);
        animationSet.setRepeatMode(Animation.RESTART);

        TranslateAnimation move = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, sign * 0.70f,
                Animation.RELATIVE_TO_PARENT, sign * -0.70f,
                Animation.RELATIVE_TO_PARENT, 0,
                Animation.RELATIVE_TO_PARENT, 0);
        move.setStartOffset(0);/*from   www. jav a2s.  c  o m*/
        move.setDuration(speed);
        move.setFillAfter(true);
        animationSet.addAnimation(move);
        view.startAnimation(animationSet);
    }
}

Related Tutorials