0
我有一個活動的根佈局是一個抽屜佈局,主要內容是一個視圖分頁器(和com.astuetz.viewpager.extensions.PagerSlidingTabStrip協助viewpager。現在我想要做的是在導航抽屜選擇特定項目,視圖尋呼機(與標籤名條沿)獲取一個片段取代我的活動佈局文件是這樣的:交換ViewPager與單個片段
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.astuetz.viewpager.extensions.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dip"
android:background="@drawable/background_tab"
app:underlineColor="#E67E22"
app:indicatorColor="#E67E22" />
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tabs"
tools:context=".UserActivity" >
</android.support.v4.view.ViewPager>
<FrameLayout android:id="@+id/fragmentToSwap"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#666"
android:background="#E8E8E8"
/>
</android.support.v4.widget.DrawerLayout>
現在,這是我努力用片段替換視圖尋呼機我對這個我自己也不太確定,有點困惑哪個元素可以替換掉方法
UserProfileActivity userProfileFragment = new UserProfileActivity();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragmentToSwap, userProfileFragment);
transaction.addToBackStack(null);
transaction.commit();
當前正在發生的是新的片段元素與視圖尋呼機重疊,而我仍然能夠在後臺使用視圖尋呼機。請幫我弄明白。
這種能見度的工作原理! :D 雖然如你所說,你的第二個想法對我來說也更有意義。當我得到時間並讓你知道它是如何發生的時候,我會試試。 (我會接受你的答案後,我試試這個:P) – gitter
它的工作原理:D謝謝 – gitter