The basic unit of the Android UI is the View. A View represents a widget that has an appearance on the screen. An Activity contains Views and ViewGroups. Examples of widgets are buttons, labels, text boxes, etc. One or more Views can be grouped together into a ViewGroup. A ViewGroup provides the layout in which you can order the appearance and sequence of views. Examples of View groups are LinearLayout, Relative Layout, etc. A ViewGroup derives from the base class android.view.ViewGroup. The LinearLayout arranges views in a single column or a single row. It displays child View elements in a linear direction, either vertically or horizontally. Like a box, it contains controls inside. Controls are drawn one after another either horizontally or vertically according to the orientation of the layout. When dealing with a linear layout there are five properties that we can deal with:
Activity
View
ViewGroup
View group
LinearLayout
Relative Layout
android.view.ViewGroup
<?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"> <TextView android:text= "First Layout" android:background= "#aa0000" android:textColor="#ffffffff" android:layout_width= "100px" android:layout_height= "50px"/> <TextView android:text= "Second Layout" android:background= "#00aa00" android:textColor="#ffffffff" android:layout_width= "100px" android:layout_height= "50px"/> <TextView android:text= "Thired Layout" android:background= "#0000aa" android:textColor="#ffffffff" android:layout_width= "100px" android:layout_height= "50px" /></LinearLayout>Output:
Horizontal Orientation: <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:text= "First Layout" android:background= "#aa0000" android:textColor="#ffffffff" android:layout_width= "70px" android:layout_height= "50px"/> <TextView android:text= "Second Layout" android:background= "#00aa00" android:textColor="#ffffffff" android:layout_width= "70px" android:layout_height= "50px"/> <TextView android:text= "Thired Layout" android:background= "#0000aa" android:textColor="#ffffffff" android:layout_width= "70px" android:layout_height= "50px" /></LinearLayout>Output:
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: