如何做出一个花哨的透明菜单,如“共享菜单”在Android画廊? [英] How to make a fancy transparent menu like the "share menu" in Android gallery?

查看:197
本文介绍了如何做出一个花哨的透明菜单,如“共享菜单”在Android画廊?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android 2.2.2设备上,画廊看起来很不错。我想在自己的应用程序中做的是按下一个按钮,然后显示如下所示的菜单:

On my Android 2.2.2 device the gallery looks really nice. What I would love to do in my own app is to press a button and then show a menu that looks like this:

这是否使用任何标准Android主题/样式?有人知道一个示例代码有这样的菜单吗?

Is this using any standard Android themes / styles? Does anybody know of an example code to have a menu like this?

编辑:
我想通过一个对话框可以模仿这个菜单。为了简化我在这个例子中不使用ListView,只有一个TextView条目的对话框:

I figured out that one could mimic this menu with a Dialog. To simplify things I'm not using a ListView in this example, just a single TextView entry for the dialog:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/layout_root"
              android:orientation="vertical"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              >
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:textColor="#FFF"
              android:padding="10dp"
              />
</LinearLayout>

当我按下按钮时显示对话框:

Showing the dialog when I press a button:

                Dialog dialog = new Dialog(MyActivity.this);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

                dialog.setContentView(R.layout.custom_dialog);

                TextView text = (TextView) dialog.findViewById(R.id.text);
                text.setText("Test option 1");

                WindowManager.LayoutParams WMLP = dialog.getWindow().getAttributes();
                WMLP.gravity = (Gravity.BOTTOM | Gravity.LEFT);
                WMLP.x = 0;
                WMLP.y = 0;
                dialog.getWindow().setAttributes(WMLP);

                dialog.show();

这将创建一个接近图片菜单的对话框。然而,我仍然有两个问题:

This creates a dialog that comes close to the menu in the picture. I still have two problems, however:

1)如何在对话框的底部绘制这个小三角形,就像上面的图片中所做的那样?

1) How can I draw this little triangle at the bottom of the dialog, like it is done in the picture above?

2)应该打开对话框的按钮水平放置在底部按钮栏的中间。所以当我按下它,对话框应该显示在该按钮的正上方。我想做的是这样:

2) The button that is supposed to open the dialog is positioned horizontally in the middle of the bottom button bar. So when I press it, the dialog should be displayed right above that button. What I would like to do is this:

WMLP.x = middleButton.getLeft() + (middleButton.getWidth() / 2) - dialog.getWindow().getDecorView().getPaddingLeft() - (WMLP.width / 2);

问题是WMLP.width是-2。我想原因是布局宽度设置为wrap_content(这是-2),实际宽度在这个时候是未知的。
那么,如何确定对话框的宽度,以便我可以将它同心定位在另一个视图?

The problem is, that WMLP.width is -2. I guess the reason is that the layout width is set to "wrap_content" (which is -2) and the actual width is not known at this moment. So, how can I determine the width of the dialog so that I can position it concentrical over another view?

更新:我终于找到了一个伟大的源这样的对话框:
http: //www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/

Update: I finally found a great source for a dialog like this: http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/

这正是我想要的,我

推荐答案

你可以在当前位置添加一个PopupWindow,冷的菜单,你将需要有这个背景的图像和litle箭头绘制。

You can do this by adding a PopupWindow at the current location, for draw this cool menu you are going to need to have the image of this background and the litle arrow to draw too.

也应该阅读关于九路径Drawable获得这个完成。

Also you should read about the Nine-Path Drawable to get this done.

PS:我已经做了这个,但是用了另一张图片。

PS: I already have this done, but with another image.

这篇关于如何做出一个花哨的透明菜单,如“共享菜单”在Android画廊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆