Android Layout Types
source link: https://www.codejourney.net/2017/04/android-layout-types/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
If you’re just an Android user, you may not even know that each screen in your application has controls composed within different Layouts. Let’s see what are the main Layout Types in designing Android app.
What is a Layout ?
Layout defines a visual structure of an Activity (or app widget). It may be considered as a set of rules according to which controls (buttons, text fields, input fields etc.) are placed on the View.
Layouts structure
Basically, user interface in Android apps is built using Layouts. Each Layout is a subclass of ViewGroup class, which derives from View class, which is the basic UI building block. View is the base class for buttons, text fields etc., more precisely: for widgets (don’t confuse it with app widgets you place on your Android screen ).
The following diagram presents this hierarchy based on RelativeLayout:
RelativeLayout hierarchy, source: techotopia.com
Let’s now see what are the most important Layout Types. Below each screenshot used to present a particular Layout Type you can find its source, which leads to a tutorial or more detailed explanation on how to work with it.
Linear Layout
LinearLayout is the most basic type of Layout. When Android app is created in Visual Studio 2017, its MainActivity has by default LinearLayout set:
LinearLayout set on MoneyBack’s MainActivity
This type of Layout enforces you to put your controls in a linear direction, either horizontally or vertically:
LinearLayout, source
Relative Layout
RelativeLayout enforces to display elements in relations to each other. You can specify that, for instance, one UI element can be said to be placed on the left of another element, or on the bottom of another etc. Each UI element can also be positioned according to the layout’s borders (e.g. aligned to the right):
RelativeLayout, source
RelativeLayout is very powerful. Consider that for building mobile apps’ interfaces these can be run on multiple devices with different screens’ resolutions. RelativeLayout allows (if properly built, of course) to adjust your set of controls easily to almost every type of screen. It’s quite specific and I personally found it difficult to understand and use initially, but it seems to be worth it.
Table Layout
As its name suggests, TableLayout allows to group elements into rows and columns:
TableLayout, source
May be useful when displaying some statistics or reports.
Grid View
GridView displays items in two-dimensional grid. The list can be easily scrolled. This type of Layout is often used on screens displaying photos or similar sets of “blocks” to click:
GridView, source
Tab Layout
Tabbed layouts allow to introduce tabs in our Android application. Then, a single Activity may contain several tabs and user can easily switch between them. On each tab you can use different type of Layout.
Consider that tabs design has changed between Android 2.X and 4.X:
Tabs, source
List View
ListView allows to display a list of items. It may be used in multiple places, from short lists of menu options to long list of emails or news feed. It allows to easily and quickly present a list of items:
ListView, source
I used it in MoneyBack for displaying a very simple list of people from the database. You can check how it’s done in this public Gist (there is even no AXML layout file for it, it’s just an Activity class).
However, Android and Xamarin teams recommend to use RecyclerView for new apps development, which is said to be more advanced and flexible version of ListView. I just noticed it seems to be a bit more complex to set up. You can check more details here.
Summary
We’ve explored some basic Layout Types that can be used for grouping UI elements in Android application. Remember that all types of layouts we’ve gone through may be nested into each other (as we’ve seen for tabs – you can use tabbed layout and then in each tab “nest” any other type of layout).
It may seem to be a bit strict, that we shouldn’t just put the controls whatever we’d like to (as we are used to do in WinForms, for example ), but mobile development requires such restrictions.
Especially building for Android – as for September 2015, there were 1.5 billion registered devices running Android system. This implies thousands of different screens resolutions, which must be handled by the UI of our apps.
What types of Layouts do you use the most in your Android apps? Do you have any best practices using them ? Share your knowledge!
Related Posts
- Xamarin.Android - debugging via WiFi
In this short post, I'm going to show you a very handy feature of Android Debug…
- Xamarin - Android Intents
We've already seen what are Activities, the most basic pieces of every Android app and…
- Xamarin – Android Activities
Today we’re going to take a look at Android’s most basic and in the same…
Recommend
-
175
V- Layout 是阿里出品的基础 UI 框架,
-
8
自定义 View 2-3 定制 Layout 的内部布局 这期是 HenCoder 布局部分的最后一期:重写 onMeasure() 和 onLayout() 来定制 Layout 的内部布局。 这期虽然距离上期的时间比较久,但主要是我的个人原因,...
-
7
Android Layout: comments activity similar to Facebook advertisements I have been looking at Facebook comment activity: I keep wondering how...
-
12
Visualizing memory layout of Rust's data types5,355 viewsOct 13, 2021 Covers how a binary is exe...
-
3
The Android user interface displays the graphic and AVD layout differently advertisements I try to make a rouned EditText.I...
-
3
Android:都是Layout的BaselineAligned惹的祸 – Android开发中文站 你的位置:Android开发中文站 > Android开发 >
-
5
Home Android & Kotlin Tutorials Advanced Data Binding in...
-
6
YouTube Music gets a new settings layout for Android tablets At its I/O 2022
-
8
SwiftUI AnyLayout - smooth transitions between layout types Table of Contents In iOS 16...
-
1
Latest Gboard beta brings new layout optimized for Android tablets After r...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK