如何创建像gmail android这样的底部菜单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10855148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:15:24  来源:igfitidea点击:

How to create bottom menu like gmail android

android

提问by Huppo

I am not quite sure what kind of layout Gmail is using in Android. I suppose they use a floating ViewGroup.

我不太确定 Gmail 在 Android 中使用什么样的布局。我想他们使用浮动ViewGroup.

But for the menu on the top and bottom I really need somebody point me how to make that.

但是对于顶部和底部的菜单,我真的需要有人指点我如何制作。

回答by miguel.rodelas

I suggest you to use the Sherlock ActionBar:

我建议你使用 Sherlock ActionBar:

http://actionbarsherlock.com/

http://actionbarsherlock.com/

This allows you to easily develop an application with an action bar for every version of Android from 2.x and up.

这使您可以轻松地为 2.x 及更高版本的每个 Android 版本开发带有操作栏的应用程序。

In the sample app you can find the code to achieve what you are looking for under "Split Action Items". The idea is that you add actions from the menu as usual, but writting the following line in your manifest activity:

在示例应用程序中,您可以在“拆分操作项”下找到实现您所寻找的代码。这个想法是您像往常一样从菜单中添加操作,但在清单活动中写入以下行:

android:uiOptions="splitActionBarWhenNarrow"

Demo App with code for the Split ActionBar

带有 Split ActionBar 代码的演示应用程序

回答by matt5784

You can create a menu which will sit on the bottom of a listview using the <RelativeLayout>tag like so

您可以使用这样的<RelativeLayout>标签 创建一个位于列表视图底部的菜单

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content" >
    <ListView
      android:layout_height="wrap_content"
      android:layout_width="fill_parent" android:id="@android:id/list"
      android:listSelector="@android:color/transparent"
      android:layout_above="@+id/footer" />

    <include android:id="@+id/footer" android:layout_height="wrap_content"
      layout="@layout/mymenu" android:layout_width="fill_parent"
      android:layout_centerHorizontal="true"
      android:layout_alignParentBottom="true" >
    </include>
</RelativeLayout>

mymenu will contain a linearlayout with something like a tablelayout with a few rows (which can be textviews, imageviews, etc.) The table will sit at the bottom of your screen and the listview will be in a frame which starts at the top of the screen and ends at the top of the menu (no overlap)

mymenu 将包含一个线性布局,其中包含几行(可以是文本视图、图像视图等)的表格布局。表格将位于屏幕底部,列表视图将位于从顶部开始的框架中屏幕并在菜单顶部结束(无重叠)

You could also do the same for the top of the screen by simply having the listview say layout_below="@+id/header"instead of layout_above"@+id/footer"(or do both!)

您也可以通过简单地让列表视图layout_below="@+id/header"代替layout_above"@+id/footer"(或两者都做!)

回答by HagTheDon

This is covered on android. You have to implement a "split action bar". Note that it works in potrait view and disappears when you switch to landscape. Android Action Bar

这在android上有介绍。您必须实施“拆分操作栏”。请注意,它在纵向视图中有效,并在切换到横向时消失。 安卓操作栏

回答by kishu27

It looks like a custom ActionBarimplementation. If you put icons in a normal ActionBarand there is not enough space to display them, android creates a bottom bar on its own and display the icons there.

它看起来像一个自定义的ActionBar实现。如果你把图标放在一个正常的地方ActionBar并且没有足够的空间来显示它们,android 会自己创建一个底部栏并在那里显示图标。

I had a similar application and I chose to put my own custom bar there instead of implementing ActionBar

我有一个类似的应用程序,我选择将自己的自定义栏放在那里而不是实现ActionBar