我们可以在LinearLayout中使用ScrollView吗?

时间:2011-05-09 14:29:07

标签: android user-interface scrollview android-linearlayout

我需要在屏幕顶部设计一个不滚动内容的GUI,以及滚动顶部的内容。我想过将LinearLayout用于非滚动部分,使用ScrollView作为滚动部分。但是,当我尝试在LinearLayout之后使用ScrollView时,我收到运行时错误。是否可以将LinearLayout和ScrollView添加到父LinearLayout?

1 个答案:

答案 0 :(得分:17)

你可以

<LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  >

  <!-- non-scrolling top pane -->
  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    >

    <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="This text will not scroll"
      />

  </LinearLayout>

  <!-- scrolling bottom pane -->
  <ScrollView
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    >

    <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      >

      <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This text will scroll if it is long enough..."
        />

    </LinearLayout>

  </ScrollView>

</LinearLayout>
相关问题