开发者

Can we use a ScrollView inside a LinearLayout?

开发者 https://www.devze.com 2023-03-04 19:47 出处:网络
I need to design a GUI with content at the top of the screen that doesn\'t scroll, and content below the top part that does sc开发者_运维知识库roll. I thought about using a LinearLayout for the non-sc

I need to design a GUI with content at the top of the screen that doesn't scroll, and content below the top part that does sc开发者_运维知识库roll. I thought about using a LinearLayout for the non-scrolling part and ScrollView for the scrolling part. However, when I try to use ScrollView after a LinearLayout I get a runtime error. Is it possible to add a LinearLayout and a ScrollView to a parent LinearLayout?


You can

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

精彩评论

暂无评论...
验证码 换一张
取 消