我已經實現該方法的活性:LayoutTransition導致片段不會顯示在創建第二時間
public void pushFragment(MyFragment fragment) {
stack.add(fragment);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.main_frame_layout, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
setTitle(fragment.getTitle(this));
}
在片段,我有此onItemClickListener列表視圖:
getAppActivity().pushFragment(anotherFragment);
AnotherFragment onCreateView方法:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setHasOptionsMenu(true);
LayoutTransition t = new LayoutTransition();
container.setLayoutTransition(t);
View rootView = inflater.inflate(R.layout.another_layout, container, false);
final ViewGroup vg = (ViewGroup)rootView.findViewById(R.id.avatar_image_layout);
vg.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
// Stuff
return rootView;
}
在API級別> = 19上一切正常。 在API 18和17(我沒有在API 16上測試過)中,第一次點擊它的工作列表視圖項。然後我回去再點擊該項目的另一個時間。這次創建片段,調用onActivityCreated和onCreateView等,但不顯示片段。
編輯1: 評論隨機的東西,我發現,這個問題是:
LayoutTransition t = new LayoutTransition();
container.setLayoutTransition(t);
評論這兩條線可以解決問題,但我不知道爲什麼,我失去了動畫。 ..
當你按下後備時,你的代碼是什麼?你重寫它並使用fragment.popbackstack()? –
是的,但正如你可以從我的編輯1看到的,這個問題是其他地方 – andrew
Im避免使用我的片段上的動畫,但如果你想,我想這可能會幫助你http://stackoverflow.com/questions/9194311/pop - 片段backstack - 沒有彈出的流行動畫 –