代码之家  ›  专栏  ›  技术社区  ›  marcc

textView在线性布局内,使用长字符串崩溃

  •  1
  • marcc  · 技术社区  · 16 年前

    使用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 足够长以在布局中容纳一行以上的文本,我将崩溃:

    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)
    

    这些信息足以证明我可能做错了什么吗?当 新值 短到一行。我想试试 TableLayout 但似乎这正是 LinearLayout 是有益的。

    1 回复  |  直到 12 年前
        1
  •  0
  •   marcc    16 年前

    感谢评论中的帮助。我最终接受了这里的建议(直接删除viewanimator并使用viewflipper)。更好的应用程序,但仍然存在同样的问题。我掉了一层线性布局容器,它开始正常工作。

    我假设bhatt4982是正确的,用户界面深度太大了。

    bhatt4982,发表你的评论作为答案,以获得这方面的荣誉。