如果采用如下方式,始终无法显示fragment内容时,其中一个比较隐蔽的可能性是,R.id.ll_main_content 这个xml里面的view必须是干净的,里面不能有任何其他的子view。
fragmentManager.beginTransaction() .addToBackStack(null) //将当前fragment加入到返回栈中 .replace(R.id.ll_main_content, fragment).commit(); 干净的R.id.ll_main_content 如下:
<LinearLayout android:id="@+id/ll_main_content" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > </LinearLayout>