Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Becoming Scrollable1:58 with Ben Deitch
In this video we'll see what it takes to make a LinearLayout scrollable! Hint: Not much.
When the list of ingredients is bigger than the screen, 0:00 we would expect to be able to scroll down to see more ingredients. 0:02 But that's not what happened, instead nothing happened. 0:07 And we weren't able to see all the ingredients. 0:10 How frustrating. 0:13 So what's going on? 0:15 Well there's actually a very simple explanation, LinearLayouts don't scroll. 0:17 But ScrollViews do. 0:22 A ScrollView is a special type of frame layout that let's us scroll whatever's 0:24 inside it. 0:27 So in order to make our LinearLayout scrollable, 0:29 we just need to put it inside of a ScrollView. 0:31 Let's head over to fragment_ingredients.xml and do just that. 0:34 Let's add a line above the LinearLayout, and add a ScrollView tag. 0:40 Then, let's cut and paste the xml namespace into our ScrollView. 0:48 And since we want the same layout_width and height attributes as well, 0:56 let's copy those too. 1:01 Then let's close our tag. 1:08 And cut the closing ScrollView tag and paste it down at the bottom. 1:11 Then I'll highlight the LinearLayout and hit tab, just to add some spacing. 1:20 Nice. 1:26 Then let's read this warning. 1:26 And change this to wrap_content. 1:30 And now let's test the app. 1:34 I'll click Pancakes. 1:42 Pick some ingredients. 1:44 Rotate it, and we should be able to scroll now. 1:46 And we can. 1:50 Cool. 1:51 Turns out, that's all there is to making a LinearLayout scrollable. 1:53 Just add a ScrollView. 1:57
You need to sign up for Treehouse in order to download course files.Sign up