2013-03-05 76 views
0

我使用PopupWindow顯示一些數據,當用戶單擊操作欄上的按鈕(使用ABS)。我還使用翻譯動畫來顯示和隱藏PopupWindow,因此它從頂部下降。Android PopupWindow裏面的片段與actionbarsherlock

我想要的行爲是讓動作欄始終保持在活動中的其他所有位置(前置狀態)。但是當我展示PopupWindow時,動畫顯示它正在下降,並且在行進欄移動時重疊。如果我爲PopupWindow設置了不同的高度,它也與操作欄重疊。

有沒有一種方法可以使用ActionBarSherlock來始終在包括彈出窗口和對話框在內的其他所有窗口上顯示操作欄?或者有什麼方法將PopupWindow附加到根FrameLayout內的基礎片段?

+0

這是一個自定義佈局,顯示一個帶有數據和圖像的ListView。 – Wenger 2013-03-05 05:10:41

回答

2

在層次結構查看器中查看您的視圖。這裏的層次結構(包括ABS的位置)充當視圖層和視圖組的z索引。你可以搶層是動作欄下,並添加自定義視圖到它:

// Grab android.R.id.content's parent to encompass the actionbar & user content 
    content = ((ViewGroup) findViewById(android.R.id.content).getParent()); 

    // Make sure we inflate our menu resource before it is used 
    if (dialog == null) 
     dialog = (ViewGroup) <INFLATE SOME DIALOG/VIEWGROUP HERE>; 

    // We need this to add a view beneath the action bar 
    FrameLayout parent = (FrameLayout) content.getParent(); 
    // There needs to be some layout params set for visibility 
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.TOP); 
    // A little tricky... using negative margins can do an initial translation that hides a view 
    layoutParams.setMargins(0, -(heightOfDialog), 0, 0); 
    dialog.setLayoutParams(layoutParams); 
    parent.addView(dialog, 0); 

這應該允許您定位的對話框下方的視圖,並且仍然能夠製作動畫,你想怎麼用像TranslateAnimation這樣的類:

TranslateAnimation animation = new TranslateAnimation(leftOfContent, 0, 0, 0); 
animation.setDuration(TIME_TO_AUTO_SCROLL); 
dialog.startAnimation(animation); 
+0

所以這個解決方案將刪除'PopupWindow'並將其替換爲您可以放入FrameLayout的視圖?我喜歡PopupWindow的'setAnimationStyle()'部分,所以我只需要弄清楚如何爲視圖添加動畫。 – Wenger 2013-03-05 16:47:13

+0

我添加了動畫的起點。他們很漂亮。 – Shellum 2013-03-05 17:33:49

+0

非常感謝。那麼我如何計算'parent.addView(...)'和'dialog.startAnimation(...)'?如果我添加視圖,我會認爲它顯示在最終位置,這是我想要從屏幕頂部對其進行動畫處理的位置。 – Wenger 2013-03-05 17:37:02