您好我将textview的背景设置为
mImageAppInstallStatus.setBackgroundResource(R.drawable.downloaded);
然后我将textview的重力设置为中心,如下所示
<TextView
android:id="@+id/textview_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textColor="#ffffff"
android:gravity="center"
android:layout_alignParentLeft="true"/>
但是在设备中&lt; API 11我得到一个如下所示的stackoverflower错误..我只有在重力中心的情况下才能获得重击如果我让重力离开它的工作
java.lang.StackOverflowError
04-10 13:09:33.747: E/(6732): at android.text.Layout.measureText(Layout.java:1655)
04-10 13:09:33.747: E/(6732): at android.text.Layout.getLineMax(Layout.java:689)
04-10 13:09:33.747: E/(6732): at android.text.Layout.draw(Layout.java:340)
04-10 13:09:33.747: E/(6732): at android.text.BoringLayout.draw(BoringLayout.java:365)
04-10 13:09:33.747: E/(6732): at android.widget.TextView.onDraw(TextView.java:4322)
04-10 13:09:33.747: E/(6732): at android.view.View.draw(View.java:6920)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1651)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1649)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1649)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1649)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1649)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1649)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.View.draw(View.java:6923)
04-10 13:09:33.747: E/(6732): at android.widget.FrameLayout.draw(FrameLayout.java:357)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1651)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1649)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.View.draw(View.java:6923)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1651)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.widget.AbsListView.dispatchDraw(AbsListView.java:1487)
04-10 13:09:33.747: E/(6732): at android.view.View.draw(View.java:7026)
04-10 13:09:33.747: E/(6732): at android.widget.AbsListView.draw(AbsListView.java:2595)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1651)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.View.draw(View.java:6923)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1651)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.View.draw(View.java:6923)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1651)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1649)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1649)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.View.draw(View.java:6923)
04-10 13:09:33.747: E/(6732): at android.support.v4.view.ViewPager.draw(ViewPager.java:2153)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1651)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1649)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1649)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1649)
04-10 13:09:33.747: E/(6732): at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:769)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1649)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.View.draw(View.java:6923)
04-10 13:09:33.747: E/(6732): at android.widget.FrameLayout.draw(FrameLayout.java:357)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1651)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.drawChild(ViewGroup.java:1649)
04-10 13:09:33.747: E/(6732): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
答案 0 :(得分:1)
您的XML可能过于复杂,并且提供额外的绘图命令可能会阻止您。
如果您有太多嵌套布局视图,或者如果您有太多具有递归调用的方法,则通常会看到java.lang.StackOverflowError。
查看Android Developers blog,了解如何理想地优化复杂的布局。
另外,请不要忘记在以下主题中检查CommonsWare的答案,其中包含嵌套布局的数量: