android布局太深导致的 java.lang.StackOverflowError

阅读更多

E/AndroidRuntime( 1900): java.lang.StackOverflowError 
E/AndroidRuntime( 1900):     at android.graphics.Canvas.drawText(Canvas.java:1269) 
E/AndroidRuntime( 1900):     at android.text.Layout.draw(Layout.java:337) 
E/AndroidRuntime( 1900):     at android.widget.TextView.onDraw(TextView.java:4006) 
E/AndroidRuntime( 1900):     at android.view.View.draw(View.java:6057) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1545) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1543) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1543) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.View.draw(View.java:6060) 
E/AndroidRuntime( 1900):     at android.view.View.buildDrawingCache(View.java:5823) 
E/AndroidRuntime( 1900):     at android.view.View.getDrawingCache(View.java:5661) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1481) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.widget.AbsListView.dispatchDraw(AbsListView.java:1322) 
E/AndroidRuntime( 1900):     at android.widget.ListView.dispatchDraw(ListView.java:2841) 
E/AndroidRuntime( 1900):     at android.view.View.draw(View.java:6164) 
E/AndroidRuntime( 1900):     at android.widget.AbsListView.draw(AbsListView.java:2169) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1545) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1543) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1543) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1543) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1543) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1543) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1543) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1543) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1543) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.View.draw(View.java:6060) 
E/AndroidRuntime( 1900):     at android.widget.FrameLayout.draw(FrameLayout.java:352) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1545) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.drawChild(ViewGroup.java:1543) 
E/AndroidRuntime( 1900):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1281) 
E/AndroidRuntime( 1900):     at android.view.View.draw(View.java:6060) 
E/AndroidRuntime( 1900):     at android.widget.FrameLayout.draw(FrameLayout.java:352) 
E/AndroidRuntime( 1900):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2038) 
E/AndroidRuntime( 1900):     at android.view.ViewRoot.draw(ViewRoot.java:1233) 
E/AndroidRuntime( 1900):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1042) 
E/AndroidRuntime( 1900):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1502) 
E/AndroidRuntime( 1900):     at android.os.Handler.dispatchMessage(Handler.java:99) 
E/AndroidRuntime( 1900):     at android.os.Looper.loop(Looper.java:123) 
E/AndroidRuntime( 1900):     at android.app.ActivityThread.main(ActivityThread.java:3972) 
E/AndroidRuntime( 1900):     at java.lang.reflect.Method.invokeNative(Native Method) 
E/AndroidRuntime( 1900):     at java.lang.reflect.Method.invoke(Method.java:521) 
E/AndroidRuntime( 1900):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
E/AndroidRuntime( 1900):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:543) 
E/AndroidRuntime( 1900):     at dalvik.system.NativeStart.main(Native Method) 
I/Process (  833): Sending signal. PID: 1900 SIG: 3

 

解决方式:减少布局嵌套层数,特别是用到类似tabHost,ViewPager的控件时,要考虑到最底层的 activity 的

contentView的布局,尽量简化,多用RelativeLayout替代LinearLayout

 

同样再优化列表滑动效率的时候,简化item布局也能带来巨大的体验提升

你可能感兴趣的:(android布局太深导致的 java.lang.StackOverflowError)