Можем ли мы использовать ScrollView внутри LinearLayout? - PullRequest
8 голосов
/ 09 мая 2011

Мне нужно создать графический интерфейс с содержимым вверху экрана, которое не прокручивается, и содержимым под верхней частью, которое прокручивается.Я думал об использовании LinearLayout для не прокручиваемой части и ScrollView для прокручиваемой части.Однако, когда я пытаюсь использовать ScrollView после LinearLayout, я получаю ошибку во время выполнения.Можно ли добавить LinearLayout и ScrollView к родительскому LinearLayout?

1 Ответ

17 голосов
/ 09 мая 2011

Вы можете

<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>
...