I'm developing an Android application, one of which requires a ViewPager of images, these images will automatically transition from one to another in a time interval I set. This is already done.
The problem is that when you move from one image to another, the transition is quick, I wanted to know some way to simulate the transition of how you would slowly run your finger across the screen. Thanks in advance.
Pager Item Transition Animation
public class DepthPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.75f;
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
if (position < -1) {
view.setAlpha(0);
} else if (position <= 0) {
view.setAlpha(1);
view.setTranslationX(0);
view.setScaleX(1);
view.setScaleY(1);
} else if (position <= 1) {
view.setAlpha(1 - position);
view.setTranslationX(pageWidth * -position);
float scaleFactor = MIN_SCALE
+ (1 - MIN_SCALE) * (1 - Math.abs(position));
Log.i("SCALE", String.valueOf(scaleFactor));
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);
} else {
view.setAlpha(0);
}
}
}
Cyclic Behavior that transitions the ViewPager from Three in Three Seconds
public void controlTimeSlidePageAdvert(){
Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
if (mPagerAdverts.getCurrentItem() == mPagerAdapterAdverts.getCount() - 1)
mPagerAdverts.setCurrentItem(0);
else
mPagerAdverts.setCurrentItem(mPagerAdverts.getCurrentItem() + 1);
}
});
}
};
timer.schedule(timerTask, 1000, 3000);
}