使用 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
当一条线足够短时,它工作得很好。我曾考虑过尝试 aTableLayout
但似乎这正是 aLinearLayout
的好处。