Monthly archives: December, 2016

Android App Basics

Here we can take an example of GeoQuiz application will consist of an activity and a layout: • An activity is an instance of Activity, a class in the Android SDK. An activity is responsible for managing user interaction with a screen of information. You write subclasses of Activity to implement the functionality that your …

Providing Messaging for Auto in Android

Staying connected through messages is important to many drivers. Chat apps can let users know if a child need to be picked up, or if a dinner location has been changed. The Android framework enables messaging apps to extend their services into car dashboards using a standard user interface that lets drivers keep their eyes …

Creating A Layout Programmatically

The most common way to create a layout is by using an XML file, as you have seen in the examples in this chapter. However, it is also possible to create a layout programmatically, by instantiating the layout class and passing it to the addContentView method in an activity class. For instance, the following code is …

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 …