2015-05-14 110 views
1

我在Android的PageViewer中重疊片段。片段在ViewPager中重疊

PFB我對PageViewer

<TabHost 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="900dp" 
    android:layout_alignParentBottom="true" > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_above="@android:id/tabs" > 

      <android.support.v4.view.ViewPager 
       android:id="@+id/viewpager" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" > 
      </android.support.v4.view.ViewPager> 
     </FrameLayout> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:orientation="horizontal" > 
     </TabWidget> 
    </RelativeLayout> 
</TabHost> 

佈局我通過第一個選項卡的我的第一塊碎片說FragmentA調用它。我需要片段A1 調用這個從列表中單擊按鈕從BaseAdapter

Fragment duedateFrag = new FieldVisitFragment(); 
      FragmentTransaction ft = fragmentActivity.getSupportFragmentManager().beginTransaction(); 
      ft.replace(android.R.id.tabcontent, duedateFrag); 

      ft.commit(); 

我的片段被調用但其對viewpager重疊來取代它。 選項卡從新片段下面運行。善意幫助

事後看來,我認爲某處嵌套片段或兒童片段應該發揮作用。請指導。

+0

你有什麼用「的FrameLayout」和「android.support.v4.view.ViewPager」做都是你的情況不同的正確 –

+0

我有4個選項卡,並與viewPager我我滾動這些標籤 –

+0

在每個標籤上我有單獨的片段顯示爲每個標籤 –

回答

1

我已經使用ViewPager,從PagerAdapter延伸。我認爲你沒有參考正確的佈局,你正在使用id/tabcontent。我可以舉出一個我做過的例子,我認爲你也可以遵循這個例子。

片段中的XML:

<LinearLayout 
... 
<android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="0px" 
     android:layout_weight="1" 
     android:background="@android:color/white" /> 
... 
</LinearLayout> 

在片段代碼:

mViewPager = (ViewPager) view.findViewById(R.id.viewpager); 

在ViewPager代碼,

@Override 
public Object instantiateItem(ViewGroup container, int position) { 
... 
View view = getActivity().getLayoutInflater().inflate(R.layout.pager_item, container, false); 
... 
return view 
} 

注:我沒有使用FragmentTransaction類用於顯示片段或選項卡視圖。

保持我們張貼...

+0

@Original Android:我已經發布了與總開發人員交替的問題https://stackoverflow.com/questions/30233001/fragment-does-not-get-displayed-in-viewpager –

+0

@ProjectAndroid,這幾乎就像回答兩次相同的「替代」問題。也許更好的辦法是編輯你的原始問題,儘管很多改變。這樣保留了很多評論。你認爲我現在發佈的答案有幫助嗎? –