在显示视图之前如何查找视图的宽度? [英] How to find the Width of the a view before the view is displayed?

查看:77
本文介绍了在显示视图之前如何查找视图的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在显示视图之前查找视图的宽度?我不想添加自定义视图并点击OnChanged()中的尺寸.

How to find the Width of the a view before the view is displayed? I do not want to add a custom view and tap the dimensions in the OnChanged().

推荐答案

Display display = getWindowManager().getDefaultDisplay();
View view = findViewById(R.id.YOUR_VIEW_ID);
view.measure(display.getWidth(), display.getHeight());

view.getMeasuredWidth(); // view width
view.getMeasuredHeight(); //view height

这篇关于在显示视图之前如何查找视图的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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