CoolDeep CoolDeep - 2 months ago 27
Android Question

Android slider button widget

I am a newbie of Android development. I want to implement a sliding button with animation. The effect is shown in the following video: http://www.youtube.com/watch?v=ImHe4N4mvE4. This is like "slide to unlock" effect of iphone. My question is that how to impelment this kind of effect. Is this app implemented with changeview, scrollview ?

Answer

you can put an image view with animation in a linear layout whose height is wrap content and width is fill parent

code for animation

    public static Animation inFromLeftAnimation() {
 Animation inFromLeft = new TranslateAnimation(
 Animation.RELATIVE_TO_PARENT,  -1.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
 Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,   0.0f
 );
 inFromLeft.setDuration(350);
 inFromLeft.setInterpolator(new AccelerateInterpolator());
 return inFromLeft;
 }
public static Animation outToLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
 Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  -1.0f,
 Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,   0.0f
);
outtoLeft.setDuration(350);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}