Open yhz61010 opened 9 years ago
Same issue for me. When you add onPageChangeListener to your sliderShow, you can see that "onPageSelected" method from listener is called X-times (where X is slides count) for first slide (only once, after initialization) - there is probably the problem. And because onImageLoadListener seems to me not working, I'm able to "fix" it only by this hack:
final int DELAY = 10000;
final int TICK = 5000;
new CountDownTimer(DELAY, TICK){
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
sliderShow.setCurrentPosition(0);
sliderShow.startAutoCycle();
}
}.start();
Assuming that you called "sliderShow.stopAutoCycle()" (it seems AutoCycle is default ON) after you init all slides (after your forEach cycle). In case you are able to detect onImageLoad event of first slide, you don't have to use Timer and just put code from onFinish() to "onEnd" method of OnImageLoadListener on your first slide...
Another approach using onImageLoadListener (works almost perfect for me):
1) create custom TextSlider class by extending BaseSliderView:
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.daimajia.slider.library.R.id;
import com.daimajia.slider.library.R.layout;
public class TextSlider extends SliderView {
public TextSlider(Context context) {
super(context);
}
public View getView() {
View v = LayoutInflater.from(this.getContext()).inflate(layout.render_type_text, null);
ImageView target = (ImageView) v.findViewById(id.daimajia_slider_image);
TextView description = (TextView) v.findViewById(id.description);
description.setText(this.getDescription());
this.bindEventAndShow(v, target);
return v;
}
}
2) use this code to init images:
sliderShow.setPresetTransformer(SliderLayout.Transformer.Default);
sliderShow.setPresetIndicator(SliderLayout.PresetIndicators.Right_Bottom);
sliderShow.setSliderTransformDuration(SLIDER_TRANSFORM, null);
sliderShow.setDuration(SLIDER_DURATION);
// important
sliderShow.stopAutoCycle();
final int[] loaded = {0};
// "Image" is my custom class
for (Image image: myClass.getImages()) {
final TextSlider sliderView = new TextSlider(this);
sliderView.description(image.getCaption());
sliderView.image(image.getUrl());
sliderView.setScaleType(SliderView.ScaleType.FitCenterCrop);
sliderView.setOnImageLoadListener(new SliderView.ImageLoadListener() {@Override
public void onStart(SliderView target) {}
@Override
public void onEnd(boolean result, SliderView target) {
loaded[0]++;
// "3" is "magic constant" (onEnd runs 3-X times, where "X" is images count)
if (loaded[0] == (myClass.getImages().size() * 3)) {
sliderShow.setCurrentPosition(0, true);
// play from first image, when all images loaded
new Handler().postDelayed(new Runnable() {@Override
public void run() {
sliderShow.startAutoCycle();
}
}, SLIDER_DURATION);
}
}
});
sliderShow.addSlider(sliderView);
}
+1 is there any solution from the author this this problem?
Thank you. I modified Your code a little (as your didn't work in my case as I OnImageLoadListener didn't work at all) and it solved two troubles. So slider starts from the first slide and I got rid of "quick slide show" at the start
In case somebody needs
mSlider.stopAutoCycle();
for (int i = 0; i < mBitmaps.size(); i++) {
final TextSlider sliderView = new TextSlider(mContext);
sliderView.description("");
sliderView.image(mBitmaps.get(i));
sliderView.setScaleType(BaseSliderView.ScaleType.FitCenterCrop);
mSlider.addSlider(sliderView);
}
mSlider.setCurrentPosition(0, true);
// play from first image, when all images loaded
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mSlider.startAutoCycle();
}
}, 5000);
}:
Hi,I also encountered the same problem.When I import ImageSlider library into Android Studio , I discovered the reason, When the function is called setPresetIndicator(PresetIndicators.Right_Bottom),
Let's look at this redraw() method
modify setItemAsSelected(mPreviousSelectedPosition); as setItemAsSelected(mPreviousSelectedPosition-1)
solve this problem!!
Add "mSlider.movePrevPosition();" as below mSlider.setDuration(5000); mSlider.movePrevPosition() //show the first dot.
Every time when I enter my fragment with SliderLayout, it doesn't start to play from first image but always from second. Does anybody encounter the same problem? I'm using the latest version of AndroidImageSlider(Version 1.1.5), Android API 14 with support library v7.
Here is my code snippet:
And my layout xml snippet: