Android Tutorial
Software Setup and Configuration
Android Studio
File Structure
Components
Core Topics
Layout
View
Button
Intent and Intent Filters
Toast
RecyclerView
Fragments
Adapters
Other UI Component
Image Loading Libraries
Date and Time
Material Design
Bars
Working with Google Maps
Chart
Animation
Database
Advance Android
Jetpack
Architecture
App Publish
App Monetization
Android provides various layouts to help developers design the UI for their applications. These layouts determine how child views are positioned and oriented on the screen. Here's an overview of some of the main UI layouts in Android:
LinearLayout:
android:orientation
to specify the direction.RelativeLayout:
android:layout_below
, android:layout_toRightOf
, etc., to describe relationships.FrameLayout:
gravity
to adjust the positioning.TableLayout:
TableRow
elements, defining the content for each row.GridLayout:
TableLayout
.ConstraintLayout:
CoordinatorLayout:
FrameLayout
.AppBarLayout
and other Design library components for effects like the collapsing toolbar.ScrollView & HorizontalScrollView:
ScrollView
allows vertical scrolling, while HorizontalScrollView
allows horizontal scrolling.PercentFrameLayout & PercentRelativeLayout:
FrameLayout
and RelativeLayout
from the percent support library, which allow you to set sizes and margins using a percentage of the parent's size.ViewStub:
Each of these layouts serves specific needs. Depending on the complexity and requirements of your UI, you might use a combination of these layouts. Also, always strive to keep your layout hierarchies as flat as possible for performance reasons. This can often be achieved with thoughtful design and the use of layouts like ConstraintLayout
.
RelativeLayout in Android examples:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, RelativeLayout!" android:layout_centerInParent="true"/> </RelativeLayout>
TableLayout examples in Android:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TableRow> <TextView android:text="Row 1, Column 1"/> <TextView android:text="Row 1, Column 2"/> </TableRow> <TableRow> <TextView android:text="Row 2, Column 1"/> <TextView android:text="Row 2, Column 2"/> </TableRow> </TableLayout>
Nested layouts in Android UI design:
LinearLayout
inside RelativeLayout
:<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_centerInParent="true"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Nested LinearLayout Example"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click me"/> </LinearLayout> </RelativeLayout>