Method for Android programming to obtain component size

This paper describes the method of obtaining component size by Android programming. Share with you for your reference, as follows:

In oncreate(), use view. Getwidth() or view. Getheiht() to obtain the width and height of the view. It seems that there is no problem. In fact, they get a value of 0, which is not the result you want?

Why?

When the oncreate () method is called, the interface is invisible and the memory loading component has not been drawn. You can't get its size.

How to get the size of the component before drawing it?

There are three proven methods:

Method 1:

Method 2:

Method 3:

Then, when the activity enters the runtime, the component size acquisition method is very simple, directly getWidth () and getHeight ()

More readers interested in Android related content can view the special topics of this site: introduction and advanced tutorial of Android development, summary of Android debugging skills and common problem solving methods, summary of Android basic component usage, summary of Android view skills, summary of Android layout skills and summary of Android control usage

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
分享
二维码
< <上一篇
下一篇>>