2011-04-27 68 views
7

我試圖用碎片重現Honeycomb GMail UI,但不能。這是我想重現Honeycomb GMail UI帶有片段

初始狀態:

+--------+---------------+ 
|  |    | 
|Accounts| Folders  | 
|  |    | 
+--------+---------------+ 

文件夾後,選擇:

+--------+---------------+ 
|  |    | 
|Folders | Items  | 
|  |    | 
+--------+---------------+ 

凡帳目,文件夾和項目的片段。 (顯然,後退按鈕應該到初始狀態)

我嘗試了以下佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:id="@+id/root"> 

    <FrameLayout 
    android:id="@+id/left_pane" android:layout_weight="1" 
    android:layout_width="0px" android:layout_height="match_parent" /> 

    <FrameLayout 
     android:id="@+id/right_pane" android:layout_weight="1.6" 
     android:layout_width="0px" android:layout_height="match_parent" /> 
</LinearLayout> 

不幸的是,因爲我不能從右邊的窗格中移動我的文件夾片段的左側窗格中,這並不工作(片段只能添加一次)。我可以創建新的文件夾,但這是相當浪費資源的,需要仔細的狀態管理(特別是當按下後退按鈕時),而且看起來並不像我想要的那樣。我試過使用3 FrameLayouts(左,中,右與權重1,1.6,2.56),但我不能讓FrameLayout崩潰時,不顯示片段。任何幫助真的讚賞

+0

...的FrameLayouts變成碎片。 ??? – 2011-04-27 23:37:31

+0

我相信這不起作用,因爲在將碎片添加到容器時不能指定佈局參數(請參閱FramentTransaction類)。 – mikea 2011-04-27 23:47:36

+0

查看Honeycomb Gallery API示例。 – 2011-04-28 00:25:34

回答

2

我認爲你可以使用3 FrameLayouts並隱藏未使用的幀。所以最初的Items框架是隱藏的。在「文件夾」框中選擇某個項目時,「帳戶」框架將被隱藏,並且「項目」名稱將變爲可見。文件夾框架(或主要活動)將不得不攔截後退按鈕,以便它可以隱藏項目框架並使賬戶框架可見。

6

使用Nicholas的帖子建議的三個框架佈局在我的應用中效果很好。爲了保持比例正確,您可能需要動態更改佈局權重(儘管我認爲可以不這樣做)。我使用這個輔助方法來處理所有這些邏輯。請注意,它需要一對夫婦;一般來說,應該清楚他們的名字需要做什麼,所以我沒有在這裏發佈。但有一點是,我有一個包含所有幀持有者的成員數組,因此此方法可以自動隱藏任何不需要的內容。

final private void showFrames(View leftFrame, View rightFrame) { 
    // Hide frames that should be gone 
    for (View frame : mContentFrames) { 
     if (frame != leftFrame && frame != rightFrame) { 
      frame.setVisibility(View.GONE); 
      Fragment frag = getFragmentManager().findFragmentById(frame.getId()); 
      if (frag != null) { 
       getFragmentTransaction().remove(frag); 
      } 
     } 
    } 

    // Set up the left frame 
    if (leftFrame != null) { 
     leftFrame.setVisibility(View.VISIBLE); 
     leftFrame.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 3)); 
    } 

    // Set up the right frame 
    if (rightFrame != null) { 
     rightFrame.setVisibility(View.VISIBLE); 
     rightFrame.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 7)); 
    } 

    // TODO: set up animation 

    // Start the transition 
    commitTransition(); 
} 

希望幫助! --randy

+0

出於好奇,你能告訴我們你的應用程序是什麼嗎?很高興看到這一行動。 – Mimminito 2012-03-20 11:49:56