ScrollView Example With Source Code In Android Studio - Androidpro.in

activityMain.xml
<?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:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

       <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:orientation="vertical">

           <TextView
               android:layout_width="match_parent"
               android:layout_height="120dp"
               android:text="Button Example"
               android:textAlignment="center"
               android:textSize="40dp"
               android:textStyle="bold"
               android:paddingTop="15dp"
               android:textColor="#FFEB3B"
               android:background="#2196F3"
               android:gravity="center_horizontal"
               android:layout_marginBottom="15dp"/>
           <Button
               android:id="@+id/button1"
               android:layout_width="match_parent"
               android:layout_height="90dp"
               android:text="Button 1"
               android:textSize="25dp"
               android:textStyle="bold"
               android:textColor="@color/white"
               android:textAllCaps="false"/>

           <Button
               android:id="@+id/button2"
               android:layout_width="match_parent"
               android:layout_height="90dp"
               android:text="Button 2"
               android:textSize="25dp"
               android:textStyle="bold"
               android:textColor="@color/white"
               android:textAllCaps="false"/>

           <Button
               android:id="@+id/button3"
               android:layout_width="match_parent"
               android:layout_height="90dp"
               android:text="Button 3"
               android:textSize="25dp"
               android:textStyle="bold"
               android:textColor="@color/white"
               android:textAllCaps="false"/>
           <Button
               android:id="@+id/button4"
               android:layout_width="match_parent"
               android:layout_height="90dp"
               android:text="Button 4"
               android:textSize="25dp"
               android:textStyle="bold"
               android:textColor="@color/white"
               android:textAllCaps="false"/>
           <Button
               android:id="@+id/button5"
               android:layout_width="match_parent"
               android:layout_height="90dp"
               android:text="Button 5"
               android:textSize="25dp"
               android:textStyle="bold"
               android:textColor="@color/white"
               android:textAllCaps="false"/>
           <Button
               android:id="@+id/button6"
               android:layout_width="match_parent"
               android:layout_height="90dp"
               android:text="Button 6"
               android:textSize="25dp"
               android:textStyle="bold"
               android:textColor="@color/white"
               android:textAllCaps="false"/>

           <Button
               android:id="@+id/button7"
               android:layout_width="match_parent"
               android:layout_height="90dp"
               android:text="Button 7"
               android:textSize="25dp"
               android:textStyle="bold"
               android:textColor="@color/white"
               android:textAllCaps="false"/>

           <Button
               android:id="@+id/button8"
               android:layout_width="match_parent"
               android:layout_height="90dp"
               android:text="Button 8"
               android:textSize="25dp"
               android:textStyle="bold"
               android:textColor="@color/white"
               android:textAllCaps="false"/>
           <Button
               android:id="@+id/button9"
               android:layout_width="match_parent"
               android:layout_height="90dp"
               android:text="Button 9"
               android:textSize="25dp"
               android:textStyle="bold"
               android:textColor="@color/white"
               android:textAllCaps="false"/>
           <Button
               android:id="@+id/button10"
               android:layout_width="match_parent"
               android:layout_height="90dp"
               android:text="Button 10"
               android:textSize="25dp"
               android:textStyle="bold"
               android:textColor="@color/white"
               android:textAllCaps="false"/>
           <Button
               android:id="@+id/button11"
               android:layout_width="match_parent"
               android:layout_height="90dp"
               android:text="Button 11"
               android:textSize="25dp"
               android:textStyle="bold"
               android:textColor="@color/white"
               android:textAllCaps="false"/>
       </LinearLayout>


    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>


ActivityMain.Java

package com.app.androidpro.myapp;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {

    private Button button1, button2, button3,button4,button5,button6,
    button7,    button8,    button9, button10, button11;
    private Intent intent , intent1,intent2,intent3,intent4,intent5,intent6,intent7,intent8,
    intent9,intent10;

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

        button1 =findViewById(R.id.button1);
        button2 =findViewById(R.id.button2);
        button3 =findViewById(R.id.button3);
        button4 =findViewById(R.id.button4);
        button5 =findViewById(R.id.button5);
        button6 =findViewById(R.id.button6);
        button7 =findViewById(R.id.button7);
        button8 =findViewById(R.id.button9);
        button9 =findViewById(R.id.button9);
        button10 =findViewById(R.id.button10);
        button11 =findViewById(R.id.button11);

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,MainActivity2.class);
                startActivity(intent);
            }
        });

        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(MainActivity.this,MainActivity3.class);
                startActivity(intent1);
            }
        });

        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent2 = new Intent(MainActivity.this,MainActivity4.class);
                startActivity(intent2);
            }
        });

        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent3 = new Intent(MainActivity.this,MainActivity5.class);
                startActivity(intent3);
            }
        });

        button5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent4 = new Intent(MainActivity.this,MainActivity6.class);
                startActivity(intent4);
            }
        });

        button6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent5 = new Intent(MainActivity.this,MainActivity7.class);
                startActivity(intent5);
            }
        });

        button7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent6 = new Intent(MainActivity.this,MainActivity8.class);
                startActivity(intent6);
            }
        });

        button8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent7 = new Intent(MainActivity.this,MainActivity9.class);
                startActivity(intent7);
            }
        });

        button9.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent8 = new Intent(MainActivity.this,MainActivity10.class);
                startActivity(intent8);
            }
        });

        button10.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent9 = new Intent(MainActivity.this,MainActivity11.class);
                startActivity(intent9);
            }
        });

        button11.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent10 = new Intent(MainActivity.this,MainActivity12.class);
                startActivity(intent10);
            }
        });

    }
}

Post a Comment

0 Comments