项目作者: STAR-ZERO

项目描述 :
[DEPRECATED]Android ViewPager with infinite/looping scroll
高级语言: Java
项目地址: git://github.com/STAR-ZERO/EternalViewPager.git
创建时间: 2018-04-29T02:28:08Z
项目社区:https://github.com/STAR-ZERO/EternalViewPager

开源协议:Apache License 2.0

下载


DEPRECATED

This repository is no longer maintained.

EternalViewPager

Download

Android ViewPager with infinite/looping scroll

This library is a bit different original Viewpager how to use. You should specify a value based on the first value or the last value.

Usage

Layout xml

  1. <com.star_zero.eternalviewpager.EternalViewPager
  2. android:id="@+id/viewpager"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent" ></com.star_zero.eternalviewpager.EternalViewPager>

Adapter

Implement class that inherit EternalPagerAdapter

  1. public class SimpleAdapter extends EternalPagerAdapter<Integer> {
  2. private static final int START = 0;
  3. private static final int END = 10;
  4. public SimpleAdapter(FragmentManager fragmentManager, Integer initialKey) {
  5. // Pass the FragmentManager and the initial value.
  6. super(fragmentManager, initialKey);
  7. }
  8. @NonNull
  9. @Override
  10. public Fragment getItem(Integer key) {
  11. // Create and return Fragment.
  12. return SimpleFragment.createInstance(key);
  13. }
  14. @Nullable
  15. @Override
  16. protected Integer getNextKey(@NonNull Integer last) {
  17. // Return the next value.
  18. // If return null, stop scrolling.
  19. if (last == END) {
  20. return null;
  21. }
  22. return last + 1;
  23. }
  24. @Nullable
  25. @Override
  26. protected Integer getPrevKey(@NonNull Integer first) {
  27. // Return the previous value.
  28. // If return null, stop scrolling.
  29. if (first == START) {
  30. return null;
  31. }
  32. return first - 1;
  33. }
  34. @Nullable
  35. @Override
  36. protected Bundle saveKeysState(@NonNull ArrayList<Integer> keys) {
  37. // Save current state.
  38. Bundle bundle = new Bundle();
  39. bundle.putIntegerArrayList("keys", keys);
  40. return bundle;
  41. }
  42. @Nullable
  43. @Override
  44. protected List<Integer> restoreKeysState(@NonNull Bundle bundle) {
  45. // Restore state.
  46. return bundle.getIntegerArrayList("keys");
  47. }
  48. }

At getNextKey or getPrevKey, you should return the next or previous value of the method parameter. If you return null, stop scrolling.

Activity/Fragment

  1. SimpleAdapter adapter = new SimpleAdapter(getSupportFragmentManager(), 0);
  2. EternalViewPager viewpager = findViewById(R.id.viewpager);
  3. viewpager.setAdapter(adapter);

For more usage, see sample.

Download

latest version: Download

  1. implementation 'com.star_zero:eternalviewpager:<latest_version>'

Known Issues

  • When scrolling continuously, it looks like reached last data. Then it can scroll again after a stop a moment. Because this library rearranges internal data when scrolling state is stopped.
  • Using with TabLayout does not work fine. It’s strange behavior when scrolling.

License

  1. Copyright 2018 Kenji Abe
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.