我正在使用的應用程序的佈局是經典的雙窗格主 - 佈局佈局。在左側菜單中,在右側面板中顯示由於按下菜單項而顯示的片段。其中一個菜單項啓動ViewPager滑動結構。這個ViewPager結構由一個ScreenSlideActivity和一個ScreenSlidePageFragment類組成。標準的第一個類包含一個指向ViewPager對象的指針,該指針包含getItem和getFragment等基本方法的適配器(ScreenSlidePagerAdapter)。如何將ViewPager侷限於片段而不是佔用整個屏幕?
一切工作正常,除了ViewPager佔據整個屏幕,而不是在右側面板。
問題:如何讓ViewPager將自己限制在右側面板,而不是佔據整個屏幕?
這裏是two_pane的佈局,通過Eclipse中生成主詳細模板項目時自動生成:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
android:showDividers="middle"
tools:context=".ItemListActivity" >
<!--
This layout is a two-pane layout for the Items
master/detail flow. See res/values-large/refs.xml and
res/values-sw600dp/refs.xml for an example of layout aliases
that replace the single-pane version of the layout with
this two-pane version.
For more on layout aliases, see:
http://developer.android.com/training/multiscreen/screensizes.html#TaskUseAliasFilters
-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/item_list"
android:name="com.company.ItemListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="@android:layout/list_content" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="20dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="20dip"
android:src="@drawable/icon" />
</LinearLayout>
<FrameLayout
android:id="@+id/item_detail_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" />
</LinearLayout>
揭開序幕的ViewPager菜單項執行此:
Intent intent = new Intent(this, ScreenSlideNewActivity.class);
startActivity(intent);
我發現了一個來自an old post here的解決方案,但是它基於不贊成使用的ActivityGroup(解決方案在底部)。
啊謝謝,我希望情況會如此。但是我不確定'監督'ViewPager的活動是否有一些基本的功能,但一個片段沒有。我會盡力實現它,並在結束時報告結果,如果結果正確,則會給予您榮譽。再次感謝! – jhulst
它完美的作品! – jhulst