ScrollView

Step 1: Start an android project.

Step 2: Open the strings.xml file and write the following code

<resources>
    <string name="app_name">ScrollView Demo</string>
    <string name="txt_horizontal">Horizontal ScrollView</string>
    <string name="txt_vertical">Vertical ScrollView</string>
    <string name="txt_title">Tom and Jerry</string>
    <string name="txt_tom_jerry_descriptiom">Tom and Jerry is an American animated franchise and series of comedy short films created in 1940 by William Hanna and Joseph Barbera. Best known for its 161 theatrical short films by Metro-Goldwyn-Mayer, the series centers on the rivalry between the titular characters of a cat named Tom and a mouse named Jerry. Many shorts also feature several recurring characters.
        In its original run, Hanna and Barbera produced 114 Tom and Jerry shorts for MGM from 1940 to 1958. During this time, they won seven Academy Awards for Best Animated Short Film, tying for first place with Walt Disney\'s Silly Symphonies with the most awards in the category. After the MGM cartoon studio closed in 1957, MGM revived the series with Gene Deitch directing an additional 13 Tom and Jerry shorts for Rembrandt Films from 1961 to 1962. Tom and Jerry then became the highest-grossing animated short film series of that time, overtaking Looney Tunes. Chuck Jones then produced another 34 shorts with Sib Tower 12 Productions between 1963 and 1967. Three more shorts were produced, The Mansion Cat in 2001, The Karate Guard in 2005, and A Fundraising Adventure in 2014, making a total of 164 shorts.
        A number of spin-offs have been made, including the television series The Tom and Jerry Show (1975), The Tom and Jerry Comedy Show (1980–1982), Tom and Jerry Kids (1990–1993), Tom and Jerry Tales (2006–2008), and The Tom and Jerry Show (2014–present). The first feature-length film based on the series, Tom and Jerry: The Movie, was released in 1992, and 13 direct-to-video films have been produced since 2002, with an upcoming live-action/animated hybrid film set to be released in 2021. A musical adaptation of the series, titled Tom and Jerry: Purr-Chance to Dream, debuted in Japan in 2019 in advance of Tom and Jerry\'s 80th anniversary.

        Tom and Jerry is an American animated franchise and series of comedy short films created in 1940 by William Hanna and Joseph Barbera. Best known for its 161 theatrical short films by Metro-Goldwyn-Mayer, the series centers on the rivalry between the titular characters of a cat named Tom and a mouse named Jerry. Many shorts also feature several recurring characters.
        In its original run, Hanna and Barbera produced 114 Tom and Jerry shorts for MGM from 1940 to 1958. During this time, they won seven Academy Awards for Best Animated Short Film, tying for first place with Walt Disney\'s Silly Symphonies with the most awards in the category. After the MGM cartoon studio closed in 1957, MGM revived the series with Gene Deitch directing an additional 13 Tom and Jerry shorts for Rembrandt Films from 1961 to 1962. Tom and Jerry then became the highest-grossing animated short film series of that time, overtaking Looney Tunes. Chuck Jones then produced another 34 shorts with Sib Tower 12 Productions between 1963 and 1967. Three more shorts were produced, The Mansion Cat in 2001, The Karate Guard in 2005, and A Fundraising Adventure in 2014, making a total of 164 shorts.
        A number of spin-offs have been made, including the television series The Tom and
    </string>
    <string name="btn_horizontal_scroll">Show Horizontal Vertical ScrollView</string>
</resources>

Step 3: Design the forms (activity_main.xml and activity_horizontal_scroll.xml) as shown in the video.

activity_main.xml file

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
    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"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="81dp"
        android:layout_marginLeft="81dp"
        android:layout_marginRight="81dp"
        android:layout_marginStart="81dp"
        android:layout_marginTop="60dp"
        android:text="@string/txt_vertical"
        android:textSize="30sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="76dp"
        android:layout_marginLeft="76dp"
        android:layout_marginRight="76dp"
        android:layout_marginStart="76dp"
        android:layout_marginTop="60dp"

        app:srcCompat="@drawable/tom_jerry" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="227dp"
        android:layout_height="45dp"
        android:layout_marginEnd="92dp"
        android:layout_marginLeft="92dp"
        android:layout_marginRight="92dp"
        android:layout_marginStart="92dp"
        android:layout_marginTop="40dp"
        android:text="@string/txt_title"
        android:textSize="30sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView" />

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="34dp"
        android:layout_marginLeft="37dp"
        android:layout_marginRight="34dp"
        android:layout_marginStart="37dp"
        android:layout_marginTop="17dp"
        android:text="@string/txt_tom_jerry_descriptiom"
        android:textSize="18sp"/>


    <Button
        android:id="@+id/button9"
        android:layout_width="401dp"
        android:layout_height="106dp"
        android:layout_marginBottom="128dp"
        android:layout_marginEnd="9dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="9dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="139dp"
        android:text="@string/btn_horizontal_scroll"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView8" />
    </androidx.appcompat.widget.LinearLayoutCompat>
</ScrollView>
</androidx.appcompat.widget.LinearLayoutCompat>

activity_horizontal_scroll.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
    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"
    android:orientation="vertical"
    tools:context=".Horizontal_Scroll">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="63dp"
        android:layout_marginLeft="63dp"
        android:layout_marginRight="63dp"
        android:layout_marginStart="63dp"
        android:layout_marginTop="73dp"
        android:text="@string/txt_horizontal"
        android:textSize="30sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">


        <ImageView
            android:id="@+id/imageView10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/tom_jerry" />

        <ImageView
            android:id="@+id/imageView11"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/mr_bean" />

        <ImageView
            android:id="@+id/imageView12"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/mr_bean3" />

        <ImageView
            android:id="@+id/imageView13"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/mr_bean2" />
    </LinearLayout>
</HorizontalScrollView>

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/txt_vertical"
        android:textSize="30sp" />
    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:id="@+id/textView10"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/txt_tom_jerry_descriptiom" />
        </LinearLayout>
    </ScrollView>
</androidx.appcompat.widget.LinearLayoutCompat>

Step 4: Open MainActivity.java file and write the following code.

package com.example.part_a5_scrollview;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.HorizontalScrollView;

public class MainActivity extends AppCompatActivity {

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

        Button btn_horizontal=(Button)findViewById(R.id.button9);

        btn_horizontal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent nxt_page=new Intent(MainActivity.this, Horizontal_Scroll.class);
                startActivity(nxt_page);
            }
        });
    }
}

Step 5: Run the project