Tuesday, February 18, 2014

Adding the image to the layout.

<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
     android:orientation=”vertical”
     android:layout_width=”fill_parent”
     android:layout_height=”fill_parent” >

<ImageView
    android:id=”@+id/icon”
    android:layout_width=”wrap_content”
    android:layout_height=”wrap_content”
    android:layout_gravity=”center_horizontal”
    android:src=”@drawable/mahi5” />

</LinearLayout>

An ImageView allows you to project an image to the device’s screen.

android:id=”@+id/icon”


The id attribute defines the unique identifier for the view in the Android system.

layout_gravity


This property defines how to place the view, both its x- and y-axis, with its parent. Here, I have defined the value as the center_horizontal constant. This value informs the Android system to place the object in the horizontal center of its container, not changing its size. You can use many other constants, such as center_vertical, top, bottom, left, right, and many more.

android:src=”@drawable/mahi5”


This property is a direct child of the ImageView class. You use this property to set the image that you would like to show up on the screen.

No comments:

Post a Comment