問題描述
我正在尋找一種獲取自定義對話框大小的方法.我經歷了 this 問題,但是唯一給出的答案是沒有用的,因為如果我嘗試 mDialog.getWindow().getAttributes().height;
它只返回 -2,這是 WRAP_CONTENT
屬性的常量我設置為對話框.我怎樣才能得到它的大小.我想知道背景圖片的 siye.
I am looking for a way to get size of a custom dialog. I went through this question, but the only answer given is pretty useless, because if I try mDialog.getWindow().getAttributes().height;
it only returns -2, which is a constant for WRAP_CONTENT
attribute which I set to dialog. How can I get the size of it. I want to know the siye for the background image.
推薦答案
實際上,在 Android 中它不像在 iOS 中那樣工作 - 你無法獲取 View
本身的大小,什么不過,您可以詢問該視圖的 ROOT 布局的大小.
Actually, in Android it doesn't work like in iOS - you can't get the size of the View
itself, what you can do, though, is to ask for the size of the ROOT layout of that view.
例如:
myDialog.this.findViewById(R.id.dialog_root_layout).getHeight());
這篇關于如何獲得對話框大小?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!