2012-04-24 56 views
0

我有兩個片段,在fragment2和片段1片段1比片段小2操縱兩個碎片

首先是讓片段2可見,比我使片段1可見,我要禁用所有按鈕和列表在片段2中,所以用戶只能控制片段1.我該怎麼做?

這裏是我的xml:

 <FrameLayout 
      android:layout_width="0dip" 
      android:layout_height="match_parent" 
      android:layout_weight="1.0" > 
      <FrameLayout 
       android:id="@+id/fragment2" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 

      <FrameLayout 
       android:id="@+id/fragment1" 
       android:layout_width="200dip" 
       android:layout_height="200dip" 
       android:visibility="gone" /> 
     </FrameLayout> 

回答

0

是不是更容易使用一個的FrameLayout作爲一個容器,然後根據需要在代碼替換片段?

例如:

<FrameLayout 
    android:id="@+id/fragmentContainer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

然後在活動包含上述佈局:

if (showFragment1()) { 
    getFragmentManager().beginTransaction(). 
     add(R.id.fragmentContainer, Fragment1.newInstance()); 
} else { 
    getFragmentManager().beginTransaction(). 
     add(R.id.fragmentContainer, Fragment2.newInstance()); 
} 

然後你可以使用在片段類onActivityCreated回調initializa你的UI。