![]() |
VOOZH | about |
In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it. A ScrollView supports Vertical scrolling only, so in order to create a horizontally scrollable view, HorizontalScrollView is used.
Attribute | Description |
|---|---|
| android:fillViewport | Defines whether the ScrollView should stretch its content to fill the viewport. |
| android:measureAllChildren | Determines whether to measure all children or just those in the VISIBLE or INVISIBLE state when measuring. Defaults to false. |
| android:alpha | alpha property of the view, as a value between 0 (completely transparent) and 1 (completely opaque). |
| android:background | A drawable to use as the background. |
| android:isScrollContainer | Set this if the view will serve as a scrolling container, meaning that it can be resized to shrink its overall window so that there will be space for an input method. |
| android:minHeight | Defines the minimum height of the view. |
| android:minWidth | Defines the minimum width of the view. |
| android:scrollbars | Defines which scrollbars should be displayed on scrolling or not. |
This example demonstrates the steps involved to create a ScrollView in Android using Kotlin.
Add the ScrollView and inside the ScrollView add a TextView to display a very long string to trigger the scroll.
As already mentioned above, Scrollview can only contain one direct child. In this case, the child is TextView. On noticing this TextView you will realize that the text added inside TextView is mentioned as @string/sample_text which refers to a string resource inside the strings.xml file.
The MainActivity will be left untouched since it serves no purpose.