今日写了一个 ViewPager 和 Fragment 配合使用,达到 ViewPager 不设置预加载(也就是一次只加载一个)和 Fragment 懒加载(也就是只加载一次)。通俗的说就是滑动或点击哪个便加载哪个,并且加载过的不再加载。下面是效果图:
下面是下载地址:
GitHub 下载地址:https://github.com/wuqingsen/FragmentLazy
优快云 下载地址:https://download.youkuaiyun.com/download/wuqingsen1/10808254
这里是在 Fragment 类中操作的,所以直接看 Fragment 类中的代码:
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.