What is scrollview

Android scrollview is used to scroll the page vertical or horizontal.

In my program you look the first screenshot the some content is hidden when the user scroll after that he will be able to see the hidden content . You will look in the second screenshot.This is possible with the help of scrollview.


ScrollView:.

In this section i am going to show the scrollview with practical example.

First open the android studio and create a project and give the name of your project like ScrollViewDemo.

The screenshots of the program is as follows:

Smiley face Smiley face

Drag and drop the one scrollview , one LinearLayout , one ImageView and two TextView from pallet . Open the activity_main.xml file and code look like this


<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="wrap_content"
    android:layout_height="wrap_content"
    tools:context=".MainActivity">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true">

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

           <ImageView
               android:layout_marginTop="0dp"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:id="@+id/image"
               android:layout_gravity="center"
               android:src="@drawable/screen"
               />
            <TextView
                android:id="@+id/txtView"
                android:layout_width="wrap_content"
                android:layout_gravity="center"
                android:text="Welcome to Scenery"
                android:textSize="30sp"
                android:layout_height="wrap_content" />
            <TextView
                android:id="@+id/txtView2"
                android:layout_width="wrap_content"
                android:layout_gravity="center"
                android:text="@string/description"
                android:textSize="20sp"
                android:layout_height="wrap_content" />




        </LinearLayout>
    </ScrollView>
       

In above code you need to do two things first to open google and download the image and copy and paste into drawable folder.

Second thing is to write this code inside the resource file. For open this file you simple explore the res folder->value folder->string.xml file.

<resources>
<string name="app_name">My Application</string>
<string name="description" >Android is a operating systm that designed for the mobile , smart phone and tablet etc. It is base on Linux operating system. It is open source . so you do not have need to pay the money. You can change the source code because it is open source. Android is developed by Google. The initial date of release is 23 sept 2008. Java language is mainly used to develope android application. We may use the other language like c++ , c# etc .
</string>
</resources>

Open the MainActivity.java file and code look like this.you do not have need to write any code in MainActivity.java file.


package com.example.niitpc.myapplication;

import android.app.DatePickerDialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;

import java.sql.Time;
import java.util.Calendar;

public class MainActivity extends AppCompatActivity {


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



    }
}



       

ScrollView

What is scrollview for video Click here

Smiley face                     Smiley face