gpt4 book ai didi

java - 如何停止 slider 上的无限循环

转载 作者:行者123 更新时间:2023-11-30 01:55:31 25 4
gpt4 key购买 nike

我正在使用 this Slider .

这是我的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDemoSlider = (SliderLayout)findViewById(R.id.slider);

HashMap<String,Integer> file_maps = new HashMap<String, Integer>();
file_maps.put("Hannibal",R.drawable.hannibal);
file_maps.put("Big Bang Theory",R.drawable.bigbang);
file_maps.put("House of Cards",R.drawable.house);
file_maps.put("Game of Thrones", R.drawable.game_of_thrones);

for(String name : file_maps.keySet()){
TextSliderView textSliderView = new TextSliderView(this);
// initialize a SliderLayout
textSliderView
.description(name)
.image(file_maps.get(name))
.setScaleType(BaseSliderView.ScaleType.Fit)
.setOnSliderClickListener(this);

//add your extra information
textSliderView.bundle(new Bundle());
textSliderView.getBundle()
.putString("extra",name);

mDemoSlider.addSlider(textSliderView);
}
mDemoSlider.setPresetTransformer(SliderLayout.Transformer.Accordion);
mDemoSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
mDemoSlider.setCustomAnimation(new DescriptionAnimation());
mDemoSlider.stopAutoCycle();
mDemoSlider.addOnPageChangeListener(this);
}

有什么方法可以阻止 slider 上的无限循环。我读到我应该添加 mDemoSlider.stopAutoCycle(); 但这没有任何效果。

最佳答案

抱歉,您不能。至少没有这个库。

我查看了代码,发现这种“无限滚动”是默认行为,如果你想禁用它,你要么实现自己的 slider ,要么为原作者提供建议和编辑...

“问题”出在 SliderLayout.java 类的这两个方法上:

/**
* move to next slide.
*/
public void moveNextPosition(boolean smooth) {

if (getRealAdapter() == null)
throw new IllegalStateException("You did not set a slider adapter");

mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1, smooth);
}

// ...

/**
* move to prev slide.
*/
public void movePrevPosition(boolean smooth) {

if (getRealAdapter() == null)
throw new IllegalStateException("You did not set a slider adapter");

mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1, smooth);
}

并且 setCurrentItem 位于 ViewPagerEx.java 类中,您可以在其中看到这种无限滚动是默认行为。 (查看 setCurrentItemInternal 方法)。

 void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity) {
if (mAdapter == null || mAdapter.getCount() <= 0) {
setScrollingCacheEnabled(false);
return;
}
if (!always && mCurItem == item && mItems.size() != 0) {
setScrollingCacheEnabled(false);
return;
}

if (item < 0) {
item = 0;
} else if (item >= mAdapter.getCount()) {
item = mAdapter.getCount() - 1;
}
final int pageLimit = mOffscreenPageLimit;
if (item > (mCurItem + pageLimit) || item < (mCurItem - pageLimit)) {
// We are doing a jump by more than one page. To avoid
// glitches, we want to keep all current pages in the view
// until the scroll ends.
for (int i=0; i<mItems.size(); i++) {
mItems.get(i).scrolling = true;
}
}
final boolean dispatchSelected = mCurItem != item;

if (mFirstLayout) {
// We don't have any idea how big we are yet and shouldn't have any pages either.
// Just set things up and let the pending layout handle things.
mCurItem = item;
triggerOnPageChangeEvent(item);
requestLayout();
} else {
populate(item);
scrollToItem(item, smoothScroll, velocity, dispatchSelected);
}
}

关于java - 如何停止 slider 上的无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32312361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com