Ranjan Bajracharya
2 min readDec 6, 2017

Android Development — Part 2 User Interface

Now, that we have installed android studio, let’s get started with it. In this section, you will talk about tools for user interface.

Activity:- It is a single focused thing the user can interaction with an app, and are also central to how a user navigates within an app.

Layouts in Android studio:- A layout defines the visual structure for a user interface, such as the UI for an activity or app widget. Their are two way to define layouts:-

1.Declare UI elements in XML( Extensible Markup Language)

2.Instantiate layout elements at runtime

Common Layouts:

  1. Linear Layout:- LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute.
  2. Relative Layout:- RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center). android:layout_alignParentTop is an attribure for RelativeLayout.
  3. . Frame Layout:- Frame Layout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that’s scalable to different screen sizes without the children overlapping each other.
  4. Constraint Layout:- ConstraintLayout allows you to create large and complex layouts with a flat view hierarchy (no nested view groups). All the power of ConstraintLayout is available directly from the Layout Editor's visual tools, because the layout API and the Layout Editor were specially built for each other. So you can build your layout with ConstraintLayout entirely by drag-and-dropping instead of editing the XML.

android.widget :

The widget package contains (mostly visual) UI elements to use on your Application screen. To create your own widget, extend View or a subclass.

Some of the widgets used :-

  1. TextView:-
  2. ImageView
  3. ViewGroup
  4. Button
  5. Label

Example of an layout:-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/reminder" />
<TextView
android:id="@+id/display_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Your Name" />
<Button
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_below="@id/times"
android:layout_alignParentRight="true"
android:text="@string/done" />
</RelativeLayout>

This layout uses RelativeLayout with EditText, TextView and Button as widgets. And those starting with android: gives attributes of the widget. Every attribute properties id defined between “ ”.F or Example android:id=”@+id/name” where

@ means it reads from res folder for project view ,

+means id is defined for first time

id defines resource type

name defines any name give to define id.

In android

dp => density independent pixels is used to defined size .

sp => scale independent pixels is used to define text size.

These only some of the terms for more detail information check android documentation.

Ranjan Bajracharya
Ranjan Bajracharya

Written by Ranjan Bajracharya

MSP 2017. Graduation in computer science and information technology. Studying MBA.

No responses yet