开发者

pop-up type view (z-index?) - android

I want to add a new view to my scene that will contain content that will change programatically througho开发者_运维知识库ut the course of my application. When it does change, it needs to pop up on the screen for 3 seconds (or a click) then disappear.

This view will change in size according to its content WRAP_CONTENT, but ideally I'd like it centered horizontally and vertically on the screen.

I'm stuck on three parts: 1) what type of view should I use for this...I was thinking Relative, but all of my playing with it has yielded no good results for what I'm trying to do 2) with respect to #1 (trying relative view), I could not get it centered properly (tried using param.leftMargin and param.topMargin with varying values but could not get it to work on different devices with different resolutions 3) also with respect to #1, I couldn't make this float over everything else on my screen (need something like a z-index or the like).

any ideas, code examples would be wonderful.

TIA


Use a custom dialog, i.e. a LinearLayout with android:theme="@android:style/Theme.Dialog" and for the class, it would be something like

public class YourCustomDialog extends Dialog implements DialogInterface

where you can implement you custom logic of what to display. Such dialog is floating and modal on top of all other views then and you can also optionally set the background to blurry, etc.

This is a typical constructor of my custom dialog - the layout would be defined in an xml layout file, which in my case is my_custom_dialog.xml:

public MyCustomDialog(Context context) {
    super(context, android.R.style.Theme);

    Window window = getWindow();
    window.requestFeature(Window.FEATURE_NO_TITLE);
    window.setGravity(Gravity.BOTTOM);
    window.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.empty));

    setContentView(R.layout.my_custom_dialog);

    // actually not necessary as it's already the default value:
    window.setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜