Summary of common methods to obtain view width and height in Android Development

This paper describes the common methods to obtain the view width and height in Android development. Share with you for your reference, as follows:

1、 Obtained from WindowManager Manager

1) When the screen is not displayed, the two methods are still in the state of 0, that is, they are valid only after setcontentview is called.

2) The activity must be set in this way to get the width and height of the view

1) Old version

2) New version

2、 Obtained by canvas in OnDraw

Three, overwrite the onSizeChanged of view, which will be called after onCreate, before onDraw.

For more Android related content, readers who are interested can view the topics on this site: summary of Android view skills, summary of Android graphics and image processing skills, introduction and advanced tutorial of Android development, summary of Android debugging skills and solutions to common problems, summary of Android multimedia operation skills (audio, video, recording, etc.) Usage Summary of Android basic components, Android layout skills summary and Android control usage summary

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>