Address: http://blog.csdn.net/xujainxing/article/details/8985063
Many articles talk about the difference between getmeasuredheight () and getheight, but they are all about "romantic nonsense ".I have to admit that I have to find the answer from the official document.
However, when the screen can actually wrap content, their values are equal. Only when the view exceeds the screen can we see their difference: getmeasuredheight () is the actual view size, the size of getheight is the size of the screen. When the screen is exceeded,Getmeasuredheight ()EqualGetheight () plus the size not displayed outside the screen
Let's take a look at this example:
[HTML]View plaincopy
- <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
- Xmlns: Tools = "http://schemas.android.com/tools"
- Android: layout_width = "match_parent"
- Android: layout_height = "match_parent"
- Android: Orientation = "vertical"
- >
- <Textview
- Android: Id = "@ + ID/textview1"
- Android: layout_width = "wrap_content"
- Android: layout_height = "fill_parent"
- Android: text = "textview"/>
- </Linearlayout>
System. Out. println ("getmeasuredheight () ------------->" + textview. getmeasuredheight ());
System. Out. println ("getheight () --------------->" + textview. getheight ());
The result is that the two are the same size, both of which are the screen size. Therefore, we simply think thatGetheight () is the actual size of the view and is also related to the layout.
The method used to obtain the control size in the middle of the activity:
[Java]View plaincopy
- Viewtreeobserver VTO = textview. getviewtreeobserver ();
- VTO. addonpredrawlistener (New viewtreeobserver. onpredrawlistener (){
- Public Boolean onpredraw (){
- System. Out. println ("getmeasuredheight () textview ------------->" + textview. getmeasuredheight ());
- System. Out. println ("getheight () textview ------------->" + textview. getheight ());
- Return true;
- }
- });
How to dynamically change the layout size:
Layoutparams Lp = Control ID. getlayoutparams ();
LP. Height = 480;
Control ID. setlayoutparams (LP );
After ID. setlayoutparams (LP) is used, you need to add ID. requestlayout ();