Fragment使用(二)

来源:互联网 发布:北京美工培训班学费 编辑:程序博客网 时间:2024/04/24 11:20

在互相嵌套的时候,子view要想得到父view的空间,activity和fragment嵌套fragment的方式是不一样的

情况一:Activity嵌套Fragment

使用

        FragmentTransaction hFt = getSupportFragmentManager().beginTransaction();

        hFt.replace(R.id.llContentZone, mFindFragment);//(要放碎片的地方,碎片)
hFt.commit();

在子view中得到父view的Scrollview:

ScrollView  outer = (ScrollView) getActivity().findViewById(R.id.outer);


情况二:Fragment嵌套Fragment

         FragmentTransaction sFt = getChildFragmentManager().beginTransaction();

         sFt .replace(R.id.llContentZone, mFindFragment);//(要放碎片的地方,碎片)
sFt .commit();

在子view中得到父view的Scrollview:

ScrollView  outer = (ScrollView) getParentFragment().getView().findViewById(R.id.outer);

0 0
原创粉丝点击