GridLayout in Android

A GridLayout is similar to a TableLayout, but the number of columns must be specified using a columnCount attribute. GridLayout example <GridLayout xmlns:android=“http://schemas.android.com/apk/res/android” android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:layout_gravity=“center” android:columnCount=“3”> <!— 1st row, spanning 3 columns —> <TextView android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:text=“Enter your name” android:layout_columnSpan=“3” android:textSize=“26sp” /> <!— 2nd row —> <TextView android:text=“First Name”/> <EditText android:id=”@+id/firstName” android:layout_width=“200dp” android:layout_columnSpan=“2”/> <!— …

TableLayout in Android

A TableLayout is used to arrange child views in rows and columns. The TableLayout class is a subclass of LinearLayout. To add a row in a TableLayout, use a TableRow element. A view directly added to a TableLayout (without a TableRow) will also occupy a row that spans all columns. Example of TableLayout <TableLayout xmlns:android=“http://schemas.android.com/apk/res/android” …

FrameLayout in Android

A FrameLayout positions its children on top of each other. By adjusting the margin and padding of a view, it is possible to lay out the view below another view. Example of FrameLayout <FrameLayout xmlns:android=“http://schemas.android.com/apk/res/android” xmlns:tools=“http://schemas.android.com/tools” android:orientation=“horizontal” android:layout_width=“match_parent” android:layout_height=“match_parent”> <Button android:text=“Button1” android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:layout_marginTop=“100dp” android:layout_marginLeft=“100dp” /> <ImageButton android:src=”@android:drawable/btn_star_big_on” android:alpha=“0.35” android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:layout_marginTop=“90dp” android:layout_marginLeft=“90dp” /> </FrameLayout> …

RelativeLayout in Android

The RelativeLayout is the most powerful layout available. All children in a RelativeLayout can be positioned relative to each other or to their parent. For example : you can tell a view to be positioned to the left or right of another view. Or, you can specify that a view is aligned to the bottom …

LinearLayout in Android

A LinearLayout is a layout that arranges its children either horizontally or vertically, depending on the value of its orientation property. The LinearLayout is the easiest layout to use. A LinearLayout can also have a gravity attribute that affects its gravity. A horizontal LinearLayout Example <LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android” xmlns:tools=“http://schemas.android.com/tools” android:orientation=“horizontal” android:layout_width=“match_parent” android:layout_height=“match_parent”> <ImageButton android:src=”@android:drawable/btn_star_big_on” android:layout_width=“wrap_content” android:layout_height=“wrap_content”/> …

Android Layouts

Layouts are important because they directly affect the look and feel of application. Technically, a layout is a view that arranges child views added to it. Android comes with a number of built-in layouts, ranging from LinearLayout, which is the easiest to use, to RelativeLayout, which is the most powerful. Layout Overview An important Android component, …

Android PendingIntent Class

A PendingIntent encapsulates an Intent and an action that will be carried out when its send method is invoked. Since a PendingIntent is a pending intent, the action is normally an operation that will be invoked some time in the future, most probably by the system. For example, a PendingIntent can be used to construct …

Android Notifications

A notification is a message on the status bar. Unlike a toast, a notification is persistent and will keep showing until it is closed or the device is shut down. A notification is an instance of android.app.Notification. The most convenient way to create a notification is by using a nested class called Builder, which can …

Android AlertDialog

AlertDialog is a window that provides feedback to the user. Unlike a Toast that fades by itself, however, an AlertDialog shows indefinitely until it loses focus. In addition, an AlertDialog can contain up to three buttons and a list of selectable items. A button added to an AlertDialog can be connected to a listener that gets …

Android APK File

An Android application is packaged into an apk file, which is basically a zip file and can be opened using WinZip or a similar program. All applications are signed with a private key. This process sounds hard enough, but thankfully Android Studio takes care of everything. When you run an Android application from inside Android …