简而言之隐藏动作条不调整大小活动简而言之、大小、动作

2023-09-12 02:08:19 作者:少女的染血 youth

我使用的是ViewPager不同片段之间滚动。有两种类型的片段,使用两个不同的菜单的资源。我无效菜单在必要时这些资源之间进行切换。这是所有工作pretty的很好,但菜单是重绘无动画。

I'm using a ViewPager to scroll between different fragments. There are two types of fragments, using two different menu resources. I'm invalidating the menu to switch between those resources when necessary. That's all working pretty well, but the menu is "redrawn" without an animation.

要prevent不必乱用个人的MenuItems我希望我可以简单地隐藏动作条,同时加载了新的菜单,显示出它的时候这样做了。这是按预期为好,但在动作条被触发的活动是调整大小。

To prevent having to mess with individual MenuItems I was hoping I could briefly hide the ActionBar while the new menu is loaded, showing it when that's done. That's working as expected as well, but the activity is resized when the ActionBar is toggled.

有没有什么办法prevent这种情况的发生,或以其他方式隐藏菜单资源之间的丑陋的过渡?

Is there any way to prevent this from happening, or otherwise hide the ugly transition between menu resources?

推荐答案

我不太明白你的问题的菜单部分,但有一个简单的解决方案,以preventing你的活动,从调整的动作条出现时,或消失了。

I didn't quite catch the menu part of your problem, but there is an easy solution to preventing your activity from resizing when the ActionBar appears or disappears.

您可以告诉动作条绘制自己的叠加模式,这意味着它会浮在活动的上方,居然是活动的布局的一部分代替。请使用android:windowActionBarOverlay在你的主题,或Window.FEATURE_ACTION_BAR_OVERLAY国旗code。

You can tell the ActionBar to draw itself in overlay mode, meaning it will float on top of the activity, in stead of actually being part of the activity's layout. Use either android:windowActionBarOverlay in your theme, or the Window.FEATURE_ACTION_BAR_OVERLAY flag from code.

您可能需要使用此功能与 actionBarSize 不变的同时,指定正确的布局的第一个视图偏移。这样一来,你的内容仍然出现下面的动作条,但由于动作条本身是覆盖,在隐藏/显示它,该活动将不会调整。

You probably want to use this feature in conjunction with the actionBarSize constant, that specifies the correct offset for the first view in your layout. This way, your content still appears below the ActionBar, but since the ActionBar itself is an overlay, upon hiding/showing it, the activity will not resize.

<SomeView
    ...
    android:layout_marginTop="?android:attr/actionBarSize" />

更多细节可以在的文档。