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