使用Android,这是布局xml文件的一部分:
<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 :(得分:0)
感谢评论中的帮助。我最终接受了这里的建议(直接删除ViewAnimator并使用ViewFlipper)。更好的应用程序,但仍然是同样的问题。我删除了一个级别的LinearLayout容器,它开始正常工作。
我假设bhatt4982是对的,UI深度太大了。
bhatt4982,将您的评论发布为获得此奖励的答案。