When you use the measure () method to calculate the height of a view, you might get an error if the view contains a relativelayout layout:
07-13 13:18:34.330:e/androidruntime (12098): java.lang.NullPointerException
07-13 13:18:34.330:e/androidruntime (12098): at Android.widget.RelativeLayout.onMeasure (relativelayout.java:465)
07-13 13:18:34.330:e/androidruntime (12098): at Android.view.View.measure (view.java:15297)
......
is probably a bug of Android, Android4.4.4 version will not have this problem.
The solution is--
Judge the system version, if it is greater than or equal to 4.4.4 ignore, otherwise:
In this view do not use relativelayout layout, change to linerlayout or framelayout what ...
Before calling the measure () method, determine the value of View.getlayoutparams () and, if NULL, set a layoutparams for the YA.
View.setlayoutparams (New Viewgroup.layoutparams (desiredwidth,desiredheight));
Of course, you measure calculate the value may be inaccurate, but at least not crash ah ...
Oh hehe ...
The first method is recommended.
Sync in: http://www.barryzhang.com/archives/423
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android:nullpointerexception when using Relativelayout with measure ()