我的Android代码存在问题:
这段代码完美无缺:
CalendarDialogFagment dialog = new CalendarDialogFagment();
dialog.setTargetFragment(this, 0);
dialog.show(getActivity().getSupportFragmentManager(), "dialog_calendar");
但是,当我尝试将其显示为片段(在平板电脑版本中)时,它变得非常迟缓和缓慢,在更新片段的布局时会造成很大的延迟。
以下是代码:
if (calendarContainer == null)
calendarContainer = getActivity().findViewById(R.id.games_calendar_container);
boolean isShown = calendarContainer.isShown();
if (!isShown) {
calendarContainer.setVisibility(View.VISIBLE);
if (calendarFragment == null) {
calendarFragment = new CalendarDialogFagment();
calendarFragment.setTargetFragment(this, 0);
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.add(R.id.games_calendar, calendarFragment, "tag");
ft.commit();
getActivity().getSupportFragmentManager().executePendingTransactions();
}
}
else{
calendarContainer.setVisibility(View.GONE);
calendarContainer = null;
}
}
XML的文件:
<LinearLayout
android:id="@+id/games_calendar_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/stagelayout"
android:orientation="vertical"
android:visibility="gone"
android:weightSum="100" >
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="95" />
<LinearLayout
android:id="@+id/games_calendar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="5"
android:background="@color/dark_gray" >
</LinearLayout>
</LinearLayout>
那么,问题可能是什么?非常感谢您的回答。