Hey Folks, Welcome to the first step toward becoming an Android developer!
We have met many students who fear to enroll for such courses as they do not possess any programming knowledge. Some find Android Studio to be very complex. If you have managed to move past these fears and enrolled for this course, let us assure you, no additional knowledge is required. All you need is, some confidence in yourself and faith in us, and by the time you are done with the course, you will be an Android developer, developing your own fascinating app.So, let’s get started! The very first thing which we are going to learn is Views. Do you know what a view is? Well, A view in layman term is a beautiful scene in which we see and where we might love to click photos.
Now, let’s discuss View in Android:
What is a View in Android? – An Overview
The View is a sight or prospect. It may be defined as the rectangular area on your mobile screen that displays texts, images, and graphics. It can be any image, text, button, or anything else that an app can display. All these are the types of Views, and in Android, these are known as ImageView, TextView, and button respectively. For more clarification just look at the below example:
So, these are the example of a View in Android. All these individual views together are known as “Layout”. You must be having more questions about this ‘layout’ which we will discuss in our next blog. For now, it is sufficient for you to know that Layout to be the collection of one or more than one views.
In the phones that you are using, everything that you see and interact with is known as “User Interface” or “UI components”.
Types of Views in Android: Most Frequently Used
- TextView: This type of view is used to display text in the app.
- ImageView: This is used to display any image in an app.
- Button: Is normal button so that user can perform some action by clicking it.
- Checkbox: Used to check a particular option.
- EditText: This is used to take input from the user.
- Radio Button: Used to check among different preferences.
The image below might help you to understand better:
Platform To Perform:-
You now know what a view is but do you know where to write? How to write? Can we write in our own language? Is there any other language in which we can write?
So, to write you need a software which is Android Studio. It is an IDE (Integrated Development Environment) which means that it has an integration of all the necessary Android files and provides an environment so that we can write the code and develop Android applications.
Now, you cannot write in a language in which you are talking to a human being. If you want to communicate with the computer with the help of Android Studio you will have to write in a language understandable by the computer. Only then, it will give you a proper output.
So, you have to write in a language called XML. XML is an acronym for eXtensible Markup Language (it is a language designed for processing, definition, and presentation text), it is just like HTML and it is used to store and transport data.
Now let’s quickly have a look on how to write this code for Views in XML.
XML Code For Views:-
Understanding The XML
As there is six statement in XML code so let’s understand this one by one.
Just closely look in which way we have written the code, you might notice that there is an opening tag “<” just in front of TextView and also noticed that TextView is written in a unique way with ‘T’ and ‘V’ in capital in TextView. This unique style is known as CamelCase conventions and it is strictly followed in XML. There is a line just in front of TextView —: xmlns:………………. We are writing this line because XML follows some standard which is defined by the Android.
This checks whether you have written the code in an appropriate way or not. Here xmlns is XML namespace which has the same use as it has in Java as it is including this URI (Uniform Resource Identifier).
Now just look at the second line to the sixth line. Do you notice some similarity? Try relating it with some equation having L.H.S and R.H.S. The LHS in each line is the attribute of a view and RHS is the appropriate value for that attribute.
Now if we talk about these, in the very first attribute width, you will find in the figure that it is something related to the width of the TextView but you might not familiar with the unit which we have used (dp), which we will talk about later.
The Third attribute is quite similar to the second one.
Next, comes id. It is something like your Roll_no which is unique i.e. each one can be easily identified. for example: In school, your attendance is marked to your roll number, marks are also given according to your roll number as there might be a student with the same name as that of yours in the class, but roll number will always be unique for everybody.
In a very similar way if there were two textView in the code then how do Android distinguish between the two? By making use of id.
The Fifth one needs no explanation as it is directly printing of the device.
The Sixth one is text size which is the size of the text that was written on the device, it is quite self-explanatory. You might have confused it with the unit (sp) which we will talk about later.
The last one is the color which is the color of the text. You might have confusion on @color/colorAccent. Let’s see where it is coming from. Have a look at the figure below.
So, you can add more color to this list and use them accordingly. If you do not want to use it in this way then just write the #FF4081 on the RHS of the TextColor attribute where #FF4081 is the color code of pink color. You can also find the color code of your favorite color and use it from http://htmlcolorcodes.com/
DP and SP:-
DP stands for density-independent pixels. It is used for padding, margins, width, height etc.
See the below figure to understand it.SP: SP stands for scale independent pixels. It is a unit of measuring much like DP which makes app look consistent across different devices of different densities. SP is used for fonts only because it adjusts the size based on the user’s preferences and setting for text size.
So according to the scale, it will increase the size of the text.
This was all about some of the basic attributes of text view. For the other views, the concept remains the same only with the attributes values differing. For more information, you can refer to https://developer.android.com/reference/android/view/View.html
Keep visiting www.acadgild.com for more updates on the Android Developer Training .