如何获得自定义对话框的大小在Android的? [英] How to get size of a custom dialog in android?

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

问题描述

我有一个自定义对话框是从对话延长。 为了把组件就可以了,我需要知道的对话框的宽度。我怎么能做到这一点? 谢谢

I have a custom Dialog which is extended from dialog. in order to place component on it, I need to know the width of the dialog. how could I do it? Thanks

编辑:

public class AnswerTypeDialog extends Dialog{
    public AnswerTypeDialog(Context context) {
        super(context);
        mContext = context;
    }

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    protected void init(){
        ll=(RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.answertype_layout, null);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(ll);
        mWindowWidth = this.getWindow().getAttributes().width;
    }
}

mWindowWidth为零。

mWindowWidth is zero.

推荐答案

您可以使用此代码段

int height=mDialog.getWindow().getDecorView().getHeight();
int width=mDialog.getWindow().getDecorView().getWidth();

这篇关于如何获得自定义对话框的大小在Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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