Android Vertical ScrollView example tutorial

Add vertical scrollview in android app to scroll up, scroll down via scroll bar.

Scroll view is a type drag n drop movable view basically used to add multiple type of layout components on single screen in vertical form so each and every component automatically fill up the app screen and when screen is full then it scroll view add a vertical scroll view and implements widgets after the screen that will become visible via drag down screen. So here is the complete step by step tutorial for Android Vertical ScrollView example tutorial.

android-project-download-code-button

ScrollView working structure.

scrollview working structure

There are a normal layout always automatically defined after starting a new android project all you have to do is start scroll view and after then again define another layout tag because scroll view always gives scroll to a particular layout not directly define widgets in it. Now after completing that process add widgets in layout file and you will be able to see that scroll view automatically added into android app.

Android Vertical ScrollView example tutorial.

Code for MainActivity.java file.

package com.android_examples.com.scrollviewvertical;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

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

Code for activity_main.xml layout file.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.android_examples.com.scrollviewvertical.MainActivity"
 android:orientation="vertical" >

 <ScrollView 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 >
 <LinearLayout 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:orientation="vertical">
 
 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="TextBox 1"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:layout_gravity="center"
 android:layout_marginTop="20dp" />
 
 <TextView
 android:id="@+id/textView2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="TextBox 2"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:layout_gravity="center"
 android:layout_marginTop="20dp" />
 
 <TextView
 android:id="@+id/textView3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="TextBox 3"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:layout_gravity="center"
 android:layout_marginTop="20dp" />
 
 <TextView
 android:id="@+id/textView4"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="TextBox 4"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:layout_gravity="center"
 android:layout_marginTop="20dp" />

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Button 1"
 android:layout_gravity="center"
 android:layout_marginTop="20dp" />
 
 <Button
 android:id="@+id/button2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Button 2"
 android:layout_gravity="center"
 android:layout_marginTop="20dp" />
 
 <Button
 android:id="@+id/button3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Button 3"
 android:layout_gravity="center"
 android:layout_marginTop="20dp" />
 
 <Button
 android:id="@+id/button4"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Button 4"
 android:layout_gravity="center"
 android:layout_marginTop="20dp" />
 
 <Button
 android:id="@+id/button5"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Button 5"
 android:layout_gravity="center"
 android:layout_marginTop="20dp" />
 <Button
 android:id="@+id/button6"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Button 6"
 android:layout_gravity="center"
 android:layout_marginTop="20dp" />
 
 
 </LinearLayout>
 </ScrollView> 
</LinearLayout>

Screenshot:

Android Vertical ScrollView example tutorial

Click Here To Download Android Vertical ScrollView example tutorial project.