【问题标题】:I added a ScrollView and it gave me an error [duplicate]我添加了一个 ScrollView,它给了我一个错误 [重复]
【发布时间】:2014-06-06 14:09:42
【问题描述】:

我这样添加了 ScrollView:

<ScrollView
  android:layout_width="fill_parent"
  android:layout_height="200dp" >     
  <TextView
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:gravity="center"
      android:text="- A Learning"
      android:textColor="#ffffff"
      android:textSize="20sp"
      android:textStyle="italic" />
  <TextView
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:gravity="center"
      android:text="- B Learning"
      android:textColor="#ffffff"
      android:textSize="20sp"
      android:textStyle="italic" />

有向上

并在图形布局中给了我这个: 渲染期间引发异常:ScrollView 只能承载一个直接子级,异常详细信息记录在 Window > Show View > Error Log 中

【问题讨论】:

  • Scrollview 可以有一个直接子级。将您的视图包含在 LinearLayout

标签: android xml eclipse


【解决方案1】:

TextView 都放在LinearLayout 中。 ScrollView 只能有一个孩子。你在这里给两个。

<ScrollView
   android:layout_width="fill_parent"
   android:layout_height="200dp" >   
   <LinearLayout  
    android:layout_width="match-parent"
    android:layout_height="match-parent">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:text="- A Learning"
        android:textColor="#ffffff"
        android:textSize="20sp"
        android:textStyle="italic" />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:text="- B Learning"
        android:textColor="#ffffff"
        android:textSize="20sp"
        android:textStyle="italic" />
   </LinearLayout>
</ScrollView>

【讨论】:

    【解决方案2】:

    您应该将ScrollView 放在一个布局中,即RelativeLayoutLinearLayout 等...所以只需将两个TextViews 放在这样的布局中,然后将此布局放在ScrollView 中。然后,如其所愿,ScrollView 将只有一个直系子代。

    【讨论】:

    • 谢谢大家,一切正常!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多