Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a linear layout scrollable?

Hey all - is it possible to make an entire linear layout scrollable when it needs to be? (when all of the elements in the layout don't fit on the main screen)?

I know it is doable with views, etc...but is there a way to incorporate everything on the layout to be scrollable at the same time?

Maybe scrollable is not the right term...basically - if one of the elements (a button in this case) doesn't entirely make it onto the main screen of the phone and I need to slide a finger down to access it...if that makes sense.

like image 957
Sapp Avatar asked Nov 22 '10 23:11

Sapp


People also ask

Can you scroll in linear layout?

You need to place ScrollView as the first child of Layout file and now put your linearlayout inside it. Now, android will decide on the basis of content and device size available whether to show a scrollable or not. Make sure linearlayout has no sibling because ScrollView can not have more than one child.

How do I add a scrollbar 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 .


2 Answers

A LinearLayout is a subclass of View, so anything you can do with a View you can with a Linear Layout.

So just use ScrollView with a single LinearLayout as a child

like image 179
pheelicks Avatar answered Oct 23 '22 21:10

pheelicks


Just exemplifying what the other guys are talking about

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent"     android:layout_height="match_parent">      <LinearLayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:gravity="center|left"         android:orientation="vertical" >           Here is your layout!      </LinearLayout>  </ScrollView> 
like image 41
Rodrigo Hernandes Avatar answered Oct 23 '22 21:10

Rodrigo Hernandes