ScrollView In Android

In android ScrollView can hold only one direct child. This means that, if you have complex layout with more views(Buttons, TextViews or any other view) then you must enclose them inside another standard layout like Table Layout, Relative Layout or Linear Layout. You can specify layout_width and layout_height to adjust width and height of screen. You can specify height and width in dp(density pixel) or px(pixel). Then after enclosing them in a standard layout, enclose the whole layout in ScrollView to make all the element or views scrollable.

We never use a Scroll View with a ListView because List View is default scrollable (i.e. vertical scrollable). More importantly, doing this affects all of the important optimizations in a List View for dealing with large lists (list items).  Just because it effectively forces the List View to display its entire list of items to fill up the infinite container supplied by a ScrollView so we don’t use it with List View.

In android default ScrollView is used to scroll the items in vertical direction and if you want to scroll the items horizontally then you need to implement horizontal ScrollView.

Horizontal ScrollView:

In android, You can scroll the elements or views in both vertical and horizontal directions. To scroll in Vertical we simply use ScrollView and to scroll in horizontal direction we need to use HorizontalScrollview.

Share with your friends:

Leave a comment

Your email address will not be published. Required fields are marked. *