如何使对话框出现在左边? [英] how to make dialog box appear on the left?

查看:230
本文介绍了如何使对话框出现在左边?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要添加OnclickListener为一个按钮,其中在我想显示关于它。我的点击在屏幕左侧的对话框试图实现这一点,但它始终在screen.Any思想的中心出现关于如何实现的?

I want to add OnclickListener for a button,where in I want to display the Dialog box on the left of the screen on click of it.I tried to implement that but it always appears on the center of the screen.Any idea on how to implement that?

推荐答案

如果我正确地理解你的问题 - 你要调整你的对话框不会显示在屏幕中央。然后看看这个code样本。

If I understand your question correctly - you want to align your dialog not appear on the center of the screen. Then look at this code sample.

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {

            if(item == 0) {

            } else if(item == 1) {

            } else if(item == 2) {

            }
        }
    });

     AlertDialog dialog = builder.create();
     dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
     WindowManager.LayoutParams WMLP = dialog.getWindow().getAttributes();


     WMLP.x = 100;   //x position
     WMLP.y = 100;   //y position

     dialog.getWindow().setAttributes(WMLP);

     dialog.show();

下面x位置的值是像素从左到右。对于y位置值是从底部到顶部。

Here x position's value is pixels from left to right. For y position value is from bottom to top.

这篇关于如何使对话框出现在左边?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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