Android ScrollView

A ScrollView is a view group that is used to create vertically scrollable views in an android application. Only a single direct child can be contained by ScrollView. For placing multiple views in a scroll view, you can create a view group like LinearLayout or ConstraintLayout as a direct child, and then you may add many other views within it. ScrollView only supports vertical scrolling, so use the HorizontalScrollView to create a display that allows horizontal scrolling.

ScrollView XML attributes

AttributeDescription
android:fillViewportDeclares whether the content is enlarged by the ScrollView to fill the viewport.

From View

AttributesDescription
android:alphaThe alpha property of the view, with a value from 0 (fully transparent) to 1 (fully opaque).
android:backgroundFor specifying background of the view.
android:clickableDefines if this view will respond to click events.
android:contentDescriptionSpecifies the text that briefly gives an idea about the view’s content.
android:idGives an identifier name for this view, for retrieving it later with View.findViewById() or Activity.findViewById().
android:isScrollContainerIf the view will provide a scrolling container, add this attribute.
android:minHeightSpecify the view’s minimum height.
android:minWidthSpecify the view’s minimum width.
android:onClickThe name of the method in the context of the view that is called when the view is clicked.
android:paddingAdds the padding according to your need.
android:scrollbarsDeclares that scroll bar displays or not when scrolling.

Demonstration

Here's a demonstration of implementing a simple ScrollView in an Android application. In the demonstration, let’s build an android application that will display text about Android using ScrollView.

1. In Android Studio, make a new project and name it as ScrollView Example. If you come across any problem in creating a new project, please refer to Android Studio Tutorial. Remember to choose the Java language.

2. Insert some strings inside the strings.xml file to display those strings in the app.

strings.xml

<resources>
    <string name ="app_name">ScrollView</string>
<string name ="text_ScrollView"> What is Android?
    The Android is an operating system that is most used on various mobile platforms around the world. It accounts for about 72.18% of the global market share by the end of July 2021. Companies like OpenHandsetAlliance developed the first Android that relied on custom versions of the Linux kernel and other open-source software. In the early stages of 2005, Google sponsored the project and acquired the entire company. In September 2008, the first Android devices hit the market, dominating the mobile industry, with features such as customizing, manufacturing, and customizing Android devices from large enterprises supported by the user-friendly community. As a result, the market is investigating the demand for developing Android-enabled devices with smart developers. Therefore, the Android operating system is a complete set of operating systems for various devices such as wearables, mobile phones, laptops, smart TVs, tablets, and set-top boxes.


    About Android Operating System
    GNU libraries are not supported, and there is no native X Windows system for them. The Linux kernel contains drivers for display, camera, flash memory, keyboard, WLAN, and sound. The Linux kernel acts as an abstraction between the hardware and the rest of the software on the smart device. It is also responsible for basic system services such as security, network stack, process management, and memory management. It is mainly developed for devices with touch displays such as smartphones, watches, and tablets. Mobile operating systems have changed a lot in the past fifteen years, from black and white feature phones to the latest smartphones, tablets, or minicomputers.
    Android software was founded in Palo Alto, California in 2003.
    Android is a powerful operating system that provides support to a variety of different applications on smart devices. These android applications are more user-friendly and easier to operate. The hardware is based on the ARM architecture platform which is supported by the Android software. Android is an open-source operating system, which means it is free of cost and anyone from around the world can use it. There are millions of Android applications that can help you manage your life in one way or another, which is why it is so popular in the market.
    Software developers who wish to create applications for the Android operating system may download a specific version of the Android Software Development Kit (SDK) as per their needs. The SDK includes a debugger, library, simulator, some documents, code examples, and tutorials. All parties can use a graphical integrated development environment (IDE) such as Android Studio or IntelliJ to write applications using Java or Kotlin Language.
Android Features
•  It provides a variety of features, such as weather information, RSS feeds (Really Simple Syndication), etc.
•  It provides push notification, GPS, and SQLite storage options.
•  It provides connectivity, such as Bluetooth, WiFi, GSM, CDMA, LTE, WiMax, NFC, etc.
•  It provides messaging functions, such as SMS and MMS.
•  It provides a web browser that uses an open-source web design engine that is linked to Google Chrome and supports HTML5 and CSS3.
</string>
</resources>

3. Insert the ScrollView and nest a TextView inside the ScrollView to display the strings that are placed in the strings.xml file.

<?xml version ="1.0" encoding ="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app ="http://schemas.android.com/apk/res-auto"
    xmlns:tools ="http://schemas.android.com/tools"
    android:layout_width ="match_parent"
    android:layout_height ="match_parent"
    tools:context =".MainActivity">


    <ScrollView
        android:layout_width ="match_parent"
        android:layout_height ="match_parent"
        android:paddingStart ="4dp"
        android:paddingEnd ="4dp"
        app:layout_constraintEnd_toEndOf ="parent"
        app:layout_constraintStart_toStartOf ="parent"
        app:layout_constraintTop_toTopOf ="parent">


        <TextView
            android:id ="@+id/scrolltext"
            style ="@style/Theme.MyApplication"
            android:layout_width ="match_parent"
            android:layout_height ="wrap_content"
            android:text ="@string/text_ScrollView"
            android:textColor ="@color/teal_700" />
    </ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

4. There is nothing to modify in the ScrollViewActivity.java file, so keep it unchanged.

import androidx.appcompat.app.AppCompatActivity;


import android.os.Bundle;


import com.example.myapplication.R;


public class ScrollViewActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scroll_view);
    }
}
ScrollView ScrollView ScrollView

Related Topics

Android Activity

What is an Activity? Android Activity is a screen in the user interface of an Android application. In this way, Android activity is very similar to the desktop application window. An...

4 minutes read.

Android Tutorial

This Android tutorial will provide you with all the concepts that will be beneficial for both beginners and advanced-level students or candidates. You can learn this tutorial to begin your...

6 minutes read.

Broadcast Receiver in Android with Example

When a device wakes up, receives a message, receives an incoming call, switches to aeroplane mode, or initiates any other system-wide action, it is said to have been broadcast in...

5 minutes read.

Android Broadcast Receivers

Android applications can send or receive broadcast messages from the Android operating system and other Androidapplications, like the publish-subscribe design pattern. When an event of interest happens,these broadcasts are sent. For...

4 minutes read.

Button Widget in Android Tutorial

Explanation: Button is a widget under Buttons section which is used to execute specific code. Example: XML file: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity">     <Button         android:id="@+id/button"         android:layout_width="wrap_content"    ...

1 minute read.

Android 9.0 Pie vs. Android 10, which one is better

Android smartphone users are always searching for new system upgrades and keep an eye on system updates whenever the next version is published. Android 9 Pie and Android Q 10 are...

5 minutes read.

Android Toast

Android is one of the most successful operating systems available in today's world. It is an open-source phone platform, compatible with almost all the devices. There are numerous features and...

3 minutes read.

ImageView Widget in Android

What you should already KNOW? You should be familiar with: 1) Creating, building, and running apps in Android Studio 2) Basics of android widgets Explanation: Image View widget is used to insert the image...

2 minutes read.

How to crop Image from Camera and Gallery in Android?

In this tutorial, we'll learn how to crop photos in the Android Gallery and Camera. There is no crop feature in this project, contrary to what was covered in the...

5 minutes read.

How to Generate QRCode in Android?

Many apps use QR codes to show data in a way that is machine-readable. Data is represented using these codes in a secure manner such that only computers, not humans,...

4 minutes read.

Dashboard UI Design in Android

One of the essential components that draw the user’s attentions into the application's operation is the dashboard design. It offers details on the application's general functionality in one location. Imagine...

11 minutes read.

Android Studio's Layout Editor

The Layout Editor allows you to efficiently create layouts by dragging UI elements from the Palette into the visual design editor instead of manually creating the layout XML file by...

8 minutes read.

Assets folder in Android

You might have noticed that unlike the Eclipse ADT (App Development Tools), the Android Studio does not have an Assets folder, which is mainly used to store the web resources...

3 minutes read.

Difference between android developer and web

From a small business to a big firm, every organization in the world of technology requires a digital market presence and only mobile applications and websites/web applications provide for digital...

4 minutes read.

Android ListView

A kind of AdapterView that displays a vertical list of scrollable views, each of which is laid out below each other is called ListView. Using adapters, items are inserted into...

4 minutes read.

Android Date picker example

How to pick date from the user in Android? Write an android example to pick date from the user and display it. Android provides control for the user to pick a date...

3 minutes read.

How to Update Gradle in Android Studio?

The Android Gradle plugin adds a number of features that are unique to develop Android apps to the Gradle build system, which is the foundation of the Android Studio development...

2 minutes read.

Android ScrollView

A ScrollView is a view group that is used to create vertically scrollable views in an android application. Only a single direct child can be contained by ScrollView. For placing...

5 minutes read.

How to insert the mobile number on an android application using EditText

Number Insertion in android application: Sometimes while dealing with numbers, we don't want to insert any string inside an number so, we premiliary define an EditText so we externally specify...

2 minutes read.

Android Emulator

A tool for creating Android virtual devices (including software and virtual hardware) on your personal desktop is known as Emulator. We can use these virtual devices as the target device...

4 minutes read.