您的位置:首页 > 移动开发 > Android开发

android Fragment View的缓存以实现重复利用

2016-08-04 22:36 330 查看
public class HotFragment extends Fragment {

private View mRootView;//缓存fragment View
private RecyclerView mRecycleView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

if(mRootView==null){
mRootView=inflater.inflate(R.layout.fragment_listview,null);
}
//缓存的rootView需要判断是否已经被加过parent, 如果有parent则从parent删除,防止发生这个rootview已经有parent的错误。
ViewGroup mViewGroup = (ViewGroup)mRootView.getParent();
if(mViewGroup!=null){
mViewGroup.removeView(mRootView);
}
return mRootView;
}

}

接下来说明下

以上代码是为了实现在多个fragement 实现View的缓存
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐