Bala
Bala

Reputation: 445

How to find out the custom dialog box width and height at runtime android

Hi i am creating one custom dialog box. It's working fine. I am allocated to the width is

fill_parent
and height is
wrap_content
How to find out their width and height at runtime.

Upvotes: 4

Views: 4149

Answers (2)

user948620
user948620

Reputation:

Try this;

AlertDialog.Builder a = new AlertDialog.Builder(this);

View v = a.create().getCurrentFocus();
v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

int height = v.getMeasuredHeight();
int width = v.getMeasuredWidth();

Upvotes: 1

Raghu Nagaraju
Raghu Nagaraju

Reputation: 3288

For any view, you can use getHeight() and getWidth() methods to get height and width information.

See this for more information.

Upvotes: 2

Related Questions