android - 如何在android中获取自定义对话框的大小?

标签 android dialog size

我有一个从对话框扩展而来的自定义对话框。 为了在上面放置组件,我需要知道对话框的宽度。我该怎么做? 谢谢

编辑:

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 为零。

最佳答案

这会起作用。

@Override
    public void onWindowFocusChanged (boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        int height=mDialog.getWindow().getDecorView().getHeight();
    int width=mDialog.getWindow().getDecorView().getWidth();
}

关于android - 如何在android中获取自定义对话框的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11392334/

相关文章:

android - WebView加载Flash动画时黑色背景

java - 在 Activity 之间传递和显示 json 数据不起作用?

android - 在捕获异常时在 Android 中显示自定义 AlertDialog

html - Canvas 绘制图像尺寸错误

c++ - 修复(锁定)std::vector 的大小

android - 在 App Billing 示例应用程序中无法正常工作

java - 我可以使用 SimpleXML 来解析结构未知的 XML 吗?

c++ - visual studio 控件编辑器为 visual c++ 生成的代码在哪里?

android - 如何在 android 的自定义对话框中显示 webview?

wpf - 如何在WPF中获取工具窗口标题栏的高度?