1
I’m developing an application Android, one of the functionalities requires having a Viewpager images, these images will be transitioning from one to the other automatically 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 fast, I wanted to know some way to simulate the transition of how you were slowly passing your finger over 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 from Viewpager to 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);
}
Post the code that makes this transition.
– ramaral
@ramaral , ready, if you know something, I thank you from now on.
– Kaynan Coelho