赞
踩
//定义放View的集合
private List<FrameLayout> mOldFrameLayout = new ArrayList<>();
//动态创建View
FrameLayout frameLayout = new FrameLayout(getContext());
//设置View的宽高
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
frameLayout.setLayoutParams(layoutParams);
//设置View的Id
frameLayout.setId(View.generateViewId());
//添加进集合
mOldFrameLayout.add(frameLayout);
//要想显示 最重要的一步 把最外层的布局 实例化后 添加对应的View
myLlParents.addView(frameLayout);
replaceFragment(mOldFrameLayout.get(i).getId(), new MyFragmentOne());
public void replaceFragment(int id,Fragment fragment) {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(id,fragment);
transaction.commit();
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。