浮动工具栏与Appcompat工具栏、Appcompat

2023-09-05 08:36:25 作者:易生峰光

如何创建与下图类似的浮动工具条中的建议,材料设计方针,并在谷歌地图应用程序。

How to create a floating toolbar like the following image as proposed in the material design guidelines and in the Google Map application.

推荐答案

我以前使用工具栏的工作,并从CommonsWare所有的意见是完全正确的。

I've worked with the Toolbar before and all the comments from CommonsWare are absolutely correct.

工具栏部件(https://developer.android.com/reference/android/support/v7/widget/Toolbar.html)绝对没有什么特别的或比任何其他不同的的ViewGroup 并没有不同的表现比任何其他的ViewGroup。

The Toolbar widget (https://developer.android.com/reference/android/support/v7/widget/Toolbar.html) have absolutely nothing special or different than any other Viewgroup and does not behave differently than any other ViewGroup.

把它放在一个的FrameLayout ,把 layout_margin 参数里面就可以了,让 layout_width 不是 match_parent ,仅此而已。

Put it inside a FrameLayout, put a layout_margin parameter on it, make the layout_width NOT match_parent and that's it.

将其放在一个的LinearLayout 方向=水平键,您可以使用 layout_weight 来控制比例的大小。或者只是使用普通的如果适合您的需求。

Put it inside an LinearLayout with orientation=horizontal and you can use the layout_weight to control the size in percentage. Or just use plain dip if that suits your needs.