With all the various screens sizes (both portrait and landscape) is it best to wrap conventional layouts (RelativeLayout
, LinearLinear
, etc) with a ScrollView
if there is even the possibility of content extending below the screen? Is there a better approach?
Update Question: What about custom inflated Views? Does the same approach apply?
I don't think I would go as far as saying that wrapping every LinearLayout
with a ScrollView
is a "best practice".
That said, in my own experience, I have often created layouts that use ScrollView
+ LinearLayout
even when I know that my content will fit on most phones. I've done this because (1) I want to support both portrait and landscape orientations (and landscape often does not have enough height to display everything) and (2) because I want to support any device my users might have (and some people do have really tiny phones).
The trick is to differentiate between cases where your LinearLayout
is just chopping the screen up into pieces vs cases where your LinearLayout
is a parent to some number of views each with their own fixed height. Two Button
s next to each other, each taking 50% of the screen width, obviously don't want a ScrollView
around them. But a form of eight EditText
fields on top of each other might do well to be wrapped in a ScrollView
, even if all eight fit on your personal device's screen just fine.
The downsides to having an "extra" or "useless" ScrollView
on larger phones is so tiny that I've never worried about it. A single extra View
instance isn't going to hurt performance or use up too much extra memory. The upside of making your app usable on tiny screens, though, is well worth it.