There are two ways for creating a user interface (UI) in Android. One of them is declarative and another one is programmatic. They are very different but are often used as one for getting the job done.
The declarative approaches will involves using XML for declaring what UI will look like and it is very similar to creating a web page with the use HTML. One can write tags and one need to specify elements for appearing right on the screen. If one can hand-coded an HTML page, one did to pretty much the same work like creating an Android screen. There is one advantage of the declarative approach by using what-you-see-is-what-you-get (WYSIWYG) tools. There is some of the tools ship right with Eclipse Android Development Tools (ADT) extension and there are others which come from third parties. XML is a readable platform for human and people who are not familiar with the Android platform as well as framework can determine the intent of the user interface.
There is one disadvantage of declarative UI approach one can get so far with XML. XML is surely great for declaring the look as well as feel of the user interface and it does not provide a way of handling user input. This is where the programmatic approach comes in.
A programmatic user interface certainly involves writing down Java code for developing UI. If one have ever done any Java AWT or Java Swing development, Android is surely the pretty much same in that respect. It is similar to various UI in other languages as well.
Basically one want to create a button, one will have to declare the button variable creating the instance of it adding it to the container and set any button properties making sense like color, text, text, size and background and many more. One can probably declare the button once it is clicked and another piece of code. All in all, one can end writing quite a few lines of Java. Everything one can do declaratively, one can also do programmatically. Java will also allow one to specify what happens when that button is clicked. This is the main advantage of programmatic approach to the user interface.
Which approach to use? The best practice is to surely use both. One would use a declarative (XML) approach for declaring everything about user interface which is static like the layout of the screen, all widgets and many more. One would then switch for programmatic approach for defining what the user will interact with various widgets etc. One would switch right to programmatic (Java) approach for defining what goes on when user interacts with various widgets in user interface. One can use XML for declaring the “button” looks like and Java for specifying what it does.
Android will organize the UI elements right into layouts and views. Everything one see, such as a button, label or text box is surely a view. Layouts will organize views such as grouping together a button as well as label or any group of the elements. Now if one has prior experience with Java AWT or Swing and layouts which are similar to Java containers and views then they are similar to Java components. Views in Android are in some cases referred to as widgets.
Just keep in mind, layout have other children. Those children are layouts themselves allowing for a complex user interface structure. A layout is responsible for allocating space for each particular child. Different layouts use various approaches to laying child widgets.
There are several main layouts which one use more frequently than others such as Linear Layout, Table Layout, Frame Layout, Relative layout and Absolute Layout.
Linear Layout is one of the simplest and most commonly used layouts. It simply lays out its children right next to each other, either vertically or horizontally. The order and arrangement of the children matters. As Linear Layout asks its children how much space they actually need and it allocates the desired space for each child right in the order they are added. So if there is an “older” child comes along and asks for the space on the screen, there would not be much left for the subsequent widgets in the layout. Another important property for linear layout is layout orientation. Its valid options are horizontal and vertical.
Table Layout will lay out its children right across a table and will consist of only other Table Row widgets. Table Row will represent a row in a table and can contain UI widgets. Table Row widgets are kept next to each other horizontally very like Linear Layout with a horizontal orientation.
For those familiar with HTML, Table Layout is very similar to the <table> element and Table Row is very similar to <tr> element. Whereas in HTML we will also have <td> for representing each cell in the table, in Android the columns are determined dynamically based on the number of views one add to the table row. Another important property for Table Layout is stretch columns which will indicate the column of the table right to stretch. One can use *to stretch all columns.
Frame Layout will place its children right on top of each other so that latest child is covering the previous like a deck of cards. This layout policy is very useful for tabs, for example. Frame layout is used as a placeholder for various other widgets adding programmatically at some other point in time
Relative Layout will lay out the children relative to each other. As such, it is very powerful as it does not require nesting unnecessary layouts for achieving certain look. Using Relative Layout will minimize the total number of widgets which needs to be drawn improving the overall performance of the application. Relative Layout will require each of the child views to have an ID set so that one can position it relative to other children.
Absolute Layout usually positions the children at different coordinates on the screen. It is the favorite layout for WYSIWYG tools and though it is very simple, it is not flexible. The user interface will surely look good on a particular screen but as the screen size, orientation or density changes, Absolute Layout will not be able to adjust.
These tutorials will give you a detailed idea about different layouts used in Android platforms for your better understanding.
Also Read,
“I think the Software Testing Course is apt for me. Webskitters Academy has offered me the best experience for online training. Every learner can learn more about several concepts. The assignments to write Test cases and Test case Scenarios equipped me to learn to work on real-time projects. I got a job at a reputed firm with the help of the placement cell of this institute. I am extremely happy.”
“After the Software Testing course at Webskitters Academy, I now have the confidence to face testing interviews. I trusted the institute and here they gave me the best of the best. The assignments are great and they helped me to think out of the box and come up with new questions. I am extremely happy and satisfied and also got a job through this institute.”
Kolkata,India
“I am 100% content with the Software Testing course at Webskitters Academy. The professionals explain every question and doubt that aroused in my mind. The entire course is explained the thorough and step-by-step process. It is very professional but the learning method and environment are very friendly.”
Kolkata,India
“I am glad that I took the decision of joining Advanced PHP and MVC (Laravel) online course at Webskitters Academy. I joined the course during the lockdown, to learn programming. However, it is turned out to be more than just a course. It became my passion. The tutors were so good and encouraging. I even got a good placement during the pandemic, just a few days after the completion of the course.”
Kolkata,India
“Learnt PHP Laravel under Swarup Kumar Saha Sir. He is very helpful and excellent trainer. I am done this course online. The training was good I improved my coding skill and also improved my communication skills.”
Kolkata,India
“Learnt PHP With Laravel under Swarup Kumar Saha Sir. He is an excellent trainer. The training was good I improved my coding skills as well as communication skills.”
“I did training on Android App Development using Core Java from here. I guess, I couldn’t have find a better faculty than Swarup Sir. The thing I liked the most is that he is very friendly and always eager to help us on any terms. Apart from teaching us Android in a very great way, he helped us in personality development too, as he always motivated us in a good way. So, I guess these training days were not only for learning but also for finding our own skills and mastering them. Thanks to Webskitters for providing us this opportunity. I would like to learn more from here.”
Kolkata,India
“I had a fantastic experience with this academy. I trained by professionals. I learned Android App Development using Core Java properly and got a job very early in a reputed software company through this academy. Many many thanks to Amit sir, Riyanka ma’am and Debjit sir.”
Kolkata,India
“I have done Android App Development using Core Java training from this academy for one month. They cover most of topic in one month. Trainer (educator) was very supportive and polite.”
Kolkata,India
“Right after completing my Android App Development with KotlinCourse at Webskitters Academy, I landed a job in a reputed firm. This was an incredible experience for me as before that I was looking for a job for almost a year but failed to get any. Thanks to the professional training I took from the experts that helped me start my career instantly.”
Kolkata,India
We are glad to have hired the students from Webskitters Academy! We have to mention that they are trained to be the professionals. From the first day onwards, they have shown their excellence, and it is very impressive. Our team is also happy with their involvement and performance. Looking forward to hire more excellent students from them!
We are happy with the quality of training that the Webskitters Academy students have received. Few of them have been on-board with us recently and they have impressed us. We would recommend our associates to hire freshers from this institute, they make sure that the students are well-trained and prepared for the industry.
We hired the students from Webskitters Academy and to our surprise we found out that they are brilliant in their work! No way we can call them students, they are professionals. They know their work, have the skills and are well-groomed for the profession. Thanks, Webskitters Academy for such a comprehensive training!
“It was for the first time that we hired students from Websitters Academy. We had some doubts regarding freshers, but to our surprise, they are very good in their work. They know exactly how to do a particular job keeping the industry standards in mind. Our organization is happy to have them. Their codes, and development skills are perfect, suitable for the industry. It proves that they have been trained comprehensively. Good work by the faculties of Webskitters Academy. We will definitely recruit more young talents from you.”