Pages Navigation Menu

Coding is much easier than you think

How To Create Scroll View in an Android Application

In this Tutorial, you will Learn, How to view the activity using scroll view

Here you go!!!!

 

Before creating an android application using Eclipse, let us see some of the key terms involved while developing this application.

Key terms involved in this project:

ScrollView: A ScrollView is a special type of FrameLayout in that it allows users to scroll through a list of views that occupy more space than the physical display. The ScrollView can contain only one child view or ViewGroup, which normally is a LinearLayout.

Note: Do not use a ListView together with the ScrollView. The ListView is designed for showing a list of related information and is optimized for dealing with large lists.

The tutorial is about how to view the activity using scroll view.

This project is developed in Eclipse 4.2 (Juno) and tested with Android 2.2

If you are new to android application project, to create a new project in Eclipse refer Creation of Android Project.

Coding:

Now let’€™s go to the coding section. This project requires following files.

Source Code:

  1. Scrollview.java

Activity Files:

  1. activity_scrollview.xml – scrollview activity (Main activity)

res – Values:

  1. strings.xml -€“ strings available in scroll view activity

Manifest file:

  1. AndroidManifest.xml

Here is the coding for the above files.

Scrollview.java:

package com.simplecodestuffs.scrollview; //package scroll view
import android.os.Bundle; // A mapping from String values to various Parcelable types
import android.app.Activity; // Required to create an activity
import android.view.Menu;  // for menu settings
public class Scrollview extends Activity {// all classes extends activity
	@Override
	protected void onCreate(Bundle savedInstanceState) {// create a new activity
		super.onCreate(savedInstanceState);
// displays scroll view activity when app starts
		setContentView(R.layout.activity_scrollview);
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_scrollview, menu);
		return true;
	}
}

activity_scrollview.xml:




    
        
        
        
       
        
        
        
        
        
        
    


Menu : activity_listview.xml



    



AndroidManifest.xml:




    

    
        
            
                

                
            
        
    



strings.xml:




    Scrollview
    
    Settings



Styles. xml:



    
    

    
    



Run the android application:

Android applications can be run on the android devices. You can either connect hardware to the system to test the application or you can use the android virtual devices (AVD) Manager to create/manage the virtual devices running on emulator to run the application.

If you are new to create a Android Virtual Device (AVD), refer Creating Android Virtual Device.

To run the application/ project, Build your project using Project -> Build Project.

Build project

This will show errors in Console window at the bottom of the working area in case your project contains.

If your build is successful, Run your application using Run -> Run or Press Ctrl +F11.

Run Project

Upon running the application, the emulator will be launched which displays the AVD on your screen.

 

 

You can see your app with the image set during the android project creation in AVD. Upon running the application, the emulator will be launched with the selected/ available AVD created on your screen.

Start Emulator

Emulator loading home page

To test your application, unlock the screen and double click on your app.

AVD Home screen

Before scrolling:

Scroll view - Before scrolling

After scrolling the screen,

Scroll view - After scrolling

Thus the android application project is executed successfully.

 


Click Here To Share This..!!
Share

2 Comments

  1. VERY GOOD

  2. You produced some decent points there. I looked on the net for the issue and found most people will go along with together with your web page.

Trackbacks/Pingbacks

  1. How to implement scroll view in java code for android? – Best Java Answer - […] In this Tutorial, you will Learn, How to view the activity using scroll view … Note: Do not…