Friday, 28 February 2014

Horizontal Marquee

Hello Friends,
            Welcome you all in the Android Development Tutorial.
            In this post we are going to learn “How to create a horizontal marquee banner with the help of Graphical Layout”.

            There are two ways of creating User Interface for an Android Application.
1)    Code
2)    Drag and Drop

Suppose I want to put a TextView widget in my Android Application, How do I do? First way is I write a code for creating a TextView. Another way is, use the widgets provide by ADT for creating a User Interface.

So today we will create a horizontal marquee without any coding. I mean with the help of Graphical Layout. Just change the properties of the widgets, according to that code will also get reflected automatically.

Steps to follow:-

1)    Create a new Android Application

Create a new Android Project.
Go to File à New à Android Application Project
Change the Application name to “Horizontal Marquee”.
Select all the default options.

Click Next
Click Next
Click Next
Click Next

Now you will have a HorizontalMarquee application on the Screen.

The Graphical View you are seeing, that is called as a Graphical Layout of the activity_main.xml

You are also seeing a default TextView (Hello World) in the middle of the GraphicalLayout.

We will modify this TextView properties to demonstrate Horizontal Marquee.

Zoom the Graphical Layout by the help of zoom in icon.

2)    Modify the TextView Properties

Click on the default TextView (“Hello World”).
On the right hand side you will be seeing a window names as Properties.

Whatever widget you will select it will represent the Properties of that Widget.

 From here we will modify the following TextView Properties.

Change the default string:-

      Go to the Text ID in TextView, click on the small right hand side button.
      Click on the New String button.
When you click you will see the following window.
Change the String Value, please give any long text here.

Change the New R.string to marqueeString
Click Ok
Click Ok
                        Your default text has been changed.

Change the Ellipsize :-

      Go to Ellipsize ID in TextView.
      Click on the right hand side small button.
      Select the marquee.

Change the Marquee Repeat Limit :-

      Go to Marquee Repeat Limit ID in TextView.
      Click on the right hand side small button.
      Select marquee_forever.

Change the Focusable and Focusable In Touch Mode:-

      Go to Focusable ID in View.
      Click on the checkbox, make it TRUE.
      Also change the Focusable In Touch Mode to TRUE.

Change the Single Line:-

      Go to the Deprecated section, select the Single Line ID and make it True by clicking on the CheckBox.

Modifications have been done. Have a look of the activity_main.xml file. Whatever properties we have modified, code related to that has been automatically added in activity_main.xml

3)    Run the application

Save all the changes. Do clean and Build.
Run the Application.
Your application will come up with the Horizontal Marquee floating in the middle of the Screen.

Please keep sharing and give your suggestions / comments.