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.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
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.e.g.:
myDialog.this.findViewById(R.id.dialog_root_layout).getHeight());
In case, if you have your own XML layouts for custom dialog.
In activity:
This
width
andheight
exacly as expected.Give it a try:
@Kormilsev Anatoliy has answered correct and I am just improving. So in the class you inherit from Dialog class just override the method: