在层次结构查看器中查看您的视图。这里的层次结构,包括 ABS 所在的位置,充当视图层和视图组的 z-index。您可以抓取操作栏下方的图层并向其添加自定义视图:
// 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);