标签:android fragment view缓存 解决方案
在Fragment onCreateView方法中缓存View
protected WeakReference<View> mRootView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// detach/attach can lead to view recreate frequently
if (mRootView == null || mRootView.get() == null) {
View view=inflater.inflate(R.layout.tab_fragment, null);
mRootView = new WeakReference<View>(view);
} else {
ViewGroup parent = (ViewGroup) mRootView.get().getParent();
if (parent != null) {
parent.removeView(mRootView.get());
}
}
return mRootView.get();
}
标签:android fragment view缓存 解决方案
原文地址:http://blog.csdn.net/hanhailong726188/article/details/45895215