如何使像&QUOT一个奇特的透明菜单;每股菜单"在Android的画廊? [英] How to make a fancy transparent menu like the "share menu" in Android gallery?

查看:137
本文介绍了如何使像&QUOT一个奇特的透明菜单;每股菜单"在Android的画廊?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid 2.2.2设备画廊看起来真的不错。我喜欢做我自己的应用程序是preSS一个按钮,然后显示一个菜单,如下所示:

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:

这是使用任何标准的Andr​​oid主题/样式?有谁知道的一个例子code有这样的菜单?

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>

显示的对话框时,我preSS按钮:

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)是应该打开对话的按钮水平放置在底部的按钮栏的中间。所以,当我preSS它,应该是正确的按钮,上面显示的对话框。 我想这样做是这样的:

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/如何对创建-quickaction-对话功能于安卓/

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

这正是我想要的,我使用它在我的应用程序了。

It's exactly what I wanted and I'm using it in my app now.

推荐答案

您可以通过添加PopupWindow在当前位置做到这一点,为得出这样你将需要有这样的背景和痘痘的形象很酷的菜单箭头画出了。

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.

你也应该阅读有关九路径绘制对象来完成这件事。

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

PS:我已经有这个工作,但与其他图像

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

这篇关于如何使像&QUOT一个奇特的透明菜单;每股菜单&QUOT;在Android的画廊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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