2013-03-05 78 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