<ol class="linenums list-paddingleft-2" style="color: rgb(30, 52, 123); margin: 0px;"><li class="L0" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161);">// 注意,这是直接拷贝的ViewPager的源码,只修改了注释处的代码</span></code></li><li class="L1" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123);">public class LazyViewPager extends ViewGroup {</span></code></li><li class="L2" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">private static final String TAG = "LazyViewPager";</span></code></li><li class="L3" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">private static final boolean DEBUG = false;</span></code></li><li class="L4" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"></code></li><li class="L5" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">private static final boolean USE_CACHE = false;</span></code></li><li class="L6" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"></code></li><li class="L7" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span style="font-size: 16px;">// 默认为1,即前后各预加载一个页面,设置为0去掉预加载</span></code></li><li class="L8" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span style="font-size: 16px; font-family: Monaco; color: rgb(0, 0, 0);"> private static final int DEFAULT_OFFSCREEN_PAGES = 0;</span></code></li><li class="L9" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"></code></li><li class="L0" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">private static final int MAX_SETTLE_DURATION = 600; // ms</span></code></li><li class="L1" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"></code></li><li class="L2" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">static class ItemInfo {</span></code></li><li class="L3" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">Object object;</span></code></li><li class="L4" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">int position;</span></code></li><li class="L5" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">boolean scrolling;</span></code></li><li class="L6" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">}</span></code></li><li class="L7" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"></code></li><li class="L8" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">private static final Comparator<ItemInfo> COMPARATOR = new Comparator<ItemInfo>() {</span></code></li><li class="L9" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">@Override</span></code></li><li class="L0" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">public int compare(ItemInfo lhs, ItemInfo rhs) {</span></code></li><li class="L1" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">return lhs.position - rhs.position;</span></code></li><li class="L2" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">}</span></code></li><li class="L3" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);">};</span></code></li><li class="L4" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76);"> ............</span></code></li><li class="L5" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px;"><code class="language-java" style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></li></ol><ol class="linenums list-paddingleft-2" style="col