Skip to main content

Linear Layout in Android - ABNHive

Linear Layout arranges other views either horizontally in a single column or vertically in a single row. It arranges its elements sequentially

Linear Layout in Android - ABNHive

Attributes


  • android: orientation—Used for arranging the controls in the container in horizontal or vertical order
  • android:layout_width—Used for defining the width of a control
  • android:layout_height—Used for defining the height of a control
  • android:padding—Used for increasing the whitespace between the boundaries of the control and its actual content
  • android:layout_weight—Used for shrinking or expanding the size of the control to consume the extra space relative to the other controls in the container
  • android:gravity—Used for aligning content within a control
  • android:layout_gravity—Used for aligning the control within the container


Example


<?xml version="1.0" encoding="utf-8"?>



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"



    android:layout_width="fill_parent" android:layout_height="fill_parent"



    android:orientation="vertical">



    <TextView android:text="RED" android:id="@+id/TextView01"



        android:layout_height="wrap_content" android:background="#f00"



        android:layout_width="fill_parent" android:layout_weight=".14"



        android:gravity="center" android:textColor="#000"></TextView>





    <TextView android:text="ORANGE" android:id="@+id/TextView02"



        android:layout_height="wrap_content" android:layout_width="fill_parent"



        android:layout_weight=".15" android:background="#ffa500"



        android:gravity="center" android:textColor="#000"></TextView>





    <TextView android:text="YELLOW" android:id="@+id/TextView03"



        android:layout_height="wrap_content" android:layout_width="fill_parent"



        android:layout_weight=".14" android:background="#ffff00"



        android:gravity="center" android:textColor="#000"></TextView>





    <TextView android:text="GREEN" android:id="@+id/TextView04"



        android:layout_height="wrap_content" android:layout_width="fill_parent"



        android:layout_weight=".15" android:background="#0f0" android:gravity="center"



        android:textColor="#000"></TextView>





    <TextView android:text="BLUE" android:id="@+id/TextView05"



        android:layout_height="wrap_content" android:layout_width="fill_parent"



        android:layout_weight=".14" android:background="#00f" android:gravity="center"



        android:textColor="#fff"></TextView>





    <TextView android:text="INDIGO" android:id="@+id/TextView06"



        android:layout_height="wrap_content" android:layout_width="fill_parent"



        android:layout_weight=".14" android:background="#4b0082"



        android:gravity="center" android:textColor="#fff"></TextView>





    <TextView android:text="VIOLET" android:id="@+id/TextView07"



        android:layout_height="wrap_content" android:layout_width="fill_parent"



        android:layout_weight=".14" android:background="#ee82ee"



        android:gravity="center" android:textColor="#000"></TextView>



</LinearLayout>



The output is like this



- Aswin Bhim Nath

Comments

Popular posts from this blog

Android Application Components Activities, Services, Broadcast Recievers, Content Providers - ABNHive

Application components are the essential building blocks of Android app development.  Each component is an entry point through which the system or a user can enter your app. There are 4 types of components in android Activities Services Broadcast receivers Content providers Let's dive into the deep.  Activities This is a component that represents a single screen with a user interface or simply an entry point for interacting with the user. Example, an email app might have one activity that shows a list of new emails. Activities work together to form a cohesive user experience in the app. For example, clicking a button on the first screen might replace that screen with another screen containing other widgets, a web page, a movie, or text information. Activities are typically created by subclassing (extending) the Android class Activity.  click here   to know more about Activity. Services This runs in the background ...

Broadcast receivers in Android - ABNHive

It responds to system-wide broadcast announcements. It used to display a persistent icon in the status bar of the device, vibrate, play a sound, flashlights, etc. to indicate to the user that something significant has happened in the background. System Generated Events The following table lists a few important system events. android.intent.action.BATTERY_CHANGED - Sticky broadcast containing the charging state, level, and other information about the battery. android.intent.action.BATTERY_LOW - Indicates low battery condition on the device. android.intent.action.BATTERY_OKAY - Indicates the battery is now okay after being low. android.intent.action.DATE_CHANGED - The date has changed. android.intent.action.REBOOT - Have the device reboot. android.intent.action.BOOT_COMPLETED  - This is broadcast once after the system has finished booting. android.intent.action.BUG_REPORT  - Show activity for reporting a bug. android.intent.action.CALL  - Perform a...