How to make a fancy transparent menu like the “share menu” in Android gallery?

亡梦爱人 提交于 2019-12-03 15:45:19

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: I already have this done, but with another image.

About the Dialog

3 Options:

  1. About drawing the triangle (actually, I think it's a square with rounded corners split by the diagonal). I'd create the large square behind (the dialog's container) and another one that would be this triangle (using an image). This would have some issues with transparency because the triangle would partially overlap the square. so maybe the triangle wouldn't be transparent.

  2. Another option, would be using a custom view. I have never tried this but I think you could specify a set of points and stroke them creating the white frame. The inside could be a painted rectangle with transparency (easy). There is something to draw a shadow with your painter object (what you use to draw text, lines, rectangles) but I believe this would be the most complicated thing to achieve using a manual drawing function.

  3. Use the source! (In other words, Android is open... see how did they do it in the source code)

About the width of the view:

When do you try to get the value? If you do it in onCreate method, it shouldn't work. Do it when the user clicks the button. If you're already doing it this time, I can't help you. It should work. I've done that many times before!

Free tip: Instead of view.getLeft (which returns the distance to its parent), using view.getLocationOnScreen is a better option.

This is probably, or at least can be, achieved using the PathShape constructs. Combined with ShapeDrawable you can build your own "dialog" control. Using The same path, you can define the clipping regions of a drawing Canvas. Finally, using ColorDrawable you can fill the canvas with the transparent color.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!