Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use a ScrollView inside a LinearLayout?

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

like image 822
ikbal Avatar asked May 09 '11 14:05

ikbal


People also ask

How do I add a scroll to LinearLayout?

I suggest you place your LinearLayout inside a ScrollView which will by default show vertical scrollbars if there is enough content to scroll. If you want the vertical scrollbar to always be shown, then add android:scrollbarAlwaysDrawVerticalTrack="true" to your ScrollView .

Which is better LinearLayout or RelativeLayout?

Relativelayout is more effective than Linearlayout. From here: It is a common misconception that using the basic layout structures leads to the most efficient layouts. However, each widget and layout you add to your application requires initialization, layout, and drawing.

Can we use linear layout in ScrollView?

ScrollView with a LinearLayout A ScrollView can contain only one child View ; however, that View can be a ViewGroup that contains several View elements, such as LinearLayout . You can nest a ViewGroup such as LinearLayout within the ScrollView , thereby scrolling everything that is inside the LinearLayout .

Can we use LinearLayout in ConstraintLayout?

Most of what can be achieved in LinearLayout and RelativeLayout can be done in ConstraintLayout.


1 Answers

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>
like image 180
Joseph Earl Avatar answered Oct 23 '22 18:10

Joseph Earl