In Android ScrollView allows multiple views that are places within the parent view group to be scrolled. Scrolling in the android application can be done in two ways either Vertically or Horizontally.
In this article, we will be discussing how to create a Horizontal ScrollView in Kotlin .
|android:fillViewport||It defines whether the horizontal scrollview should stretch its content to fill the viewport.|
|android:layout_height||Sets the height of the horizontal scroll view|
|android:layout_width||Sets the width of the horizontal scroll view|
|android:src||Sets background of the image|
|android:id||Sets unique id of the view|
Let’s start by first creating a project in Android Studio. To do so, follow these instructions:
First step is to create a new Project in Android Studio. For this follow these steps:
- Click on File, then New and then New Project and give name whatever you like
- Then, select Kotlin language Support and click next button.
- Select minimum SDK, whatever you need
- Select Empty activity and then click finish.
Modify activity_main.xml file
We need to add some images which can be used for scrolling purpose. So, we have to copy the images from our local computer path to app/res/mipmap folder.
Note: We have added the images to mipmap folder instead of drawable folder because the size of the images is very large.
Create HorizontalScrollView in MainActivity.kt file
Open app/src/main/java/yourPackageName/MainActivity.kt and do the following changes:
Run as Emulator:
- Kotlin | Retrieve Collection Parts
- DatePicker in Kotlin
- Kotlin constructor
- Kotlin Recursion
- Kotlin Higher-Order Functions
- Kotlin extension function
- Kotlin annotations
- Kotlin generics
- Kotlin Interfaces
- Kotlin Sealed Classes
- Kotlin Regular Expression
- Kotlin Array
- Kotlin Reflection
- Kotlin list : Arraylist
- Kotlin Collections
- Java Interoperability - Calling Java from Kotlin
- Java Interoperability - Calling Kotlin from Java
- Kotlin String
- Kotlin Ranges
- Kotlin | apply vs with
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.