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?
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 .
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.
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 .
Most of what can be achieved in LinearLayout and RelativeLayout can be done in ConstraintLayout.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With