尤里卡!我的解決方案是爲詳細信息活動提供一個空白的備用佈局。我膨脹佈局後,我可以檢查,看看我期望的片段是否在佈局中,如果不是,那麼我完成()。
details_view.xml在/ RES /佈局:在/ RES /佈局 - [屏幕尺寸] 這一個是你不想要顯示的詳細信息任何屏幕尺寸
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<fragment
android:name="com.website.DetailsFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/details_fragment"
android:layout_weight="75">
</fragment>
</LinearLayout>
details_view.xml在橫向模式下自己的活動片段(在我的情況下或多或少的片劑)。
<?xml version="1.0" encoding="utf-8"?>
<!-- Note: This file has an empty layout to notify
DetailsViewActivity that we should go back to landscape
and view the fragments side by side -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
只需將空的details_view.xml文件放在任何佈局文件中,該佈局文件允許並排顯示片段。
最後的DetailsViewActivity退出,如果我們想通過側回去端的代碼:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.details_view);
mDetailsView = (TopicViewFragment)getSupportFragmentManager()
.findFragmentById(R.id.details_fragment);
// We can handle the fragments side by side in the previous activity
// so lets go back there
if ((mDetailsView == null || !mDetailsView.isInLayout()) &&
getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE) {
finish();
return;
}
我也喜歡數據的少一些重疊,但這種解決方案並不差。它只會強制您將一個額外的佈局文件複製到您具有並排碎片佈局文件的同一目錄中。真的不算太糟糕。
酷。你可以回答你自己的問題並獲得積分。甚至還有一個徽章。 – Pedantic 2012-02-28 04:06:19