2009-09-07 61 views
1

使用的Android,这里是一个布局的XML文件的一部分:TextView的一个的LinearLayout里面,崩溃了一长串

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:textColor="#191919"> 

     <TextView android:id="@+id/someTextField" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:textStyle="bold" /> 

     <TextView android:id="@+id/anotherTextField" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

</LinearLayout> 

我加入了这个观点(在运行时)到ViewAnimator这样的:

ViewAnimator viewAnimator = (ViewAnimator)findViewById(R.id.viewAnimator); 
View newView = View.inflate(this, R.layout.new_view, null); 
viewAnimator.addView(newView); 
viewAnimator.showNext(); 

String newValue = "new value for the text field"; 
findViewById(R.id.deal_view).setVisibility(View.VISIBLE); 
TextView someTextField = (TextView)findViewById(R.id.someTextField); 
someTextField.setText(newValue); 

这似乎是工作的罚款,但是当newValue是足够长的时间超过1行文本的布局,我得到一个崩溃:

09-06 21:36:48.208: ERROR/AndroidRuntime(6561): Uncaught handler: thread main exiting due to uncaught exception 
09-06 21:36:48.248: ERROR/AndroidRuntime(6561): java.lang.StackOverflowError 
09-06 21:36:48.248: ERROR/AndroidRuntime(6561):  at android.view.ViewGroup.drawChild(ViewGroup.java:1486) 
09-06 21:36:48.248: ERROR/AndroidRuntime(6561):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228) 
(many more lines like this) 

这是足够的信息,看看我可能做错了什么?当newValue对于一行足够短时,它工作得很好。我想过尝试TableLayout,但看起来这正是LinearLayout的好处。

+0

只是好奇,你为什么直接使用ViewAnimator?不要ViewFlipper或ViewSwitcher完全适合你吗? – Matthias 2009-09-07 07:45:49

+0

ViewFlipper和ViewSwitcher ...我会给他们一个尝试,看看是否有所帮助...我还是很新的Android,所以感谢您的建议。 – marcc 2009-09-07 15:35:37

+1

希望你已经解决了你的问题! 但我觉得问题出在 错误/ AndroidRuntime(6561):java.lang.StackOverflowError 这通常是由于UI层次结构中的深度。 – bhatt4982 2009-09-08 07:20:22

回答

0

感谢您对评论的帮助。我最终在这里接受了建议(直接删除ViewAnimator并使用ViewFlipper)。更好的应用程序,但仍然是同样的问题。我丢弃了一层LinearLayout容器,它开始正常工作。

我假设bhatt4982是正确的,UI深度太大了。

bhatt4982,发布您的评论作为答案得到这个功劳。

相关问题