Brandon Ling
Brandon Ling

Reputation: 3919

Android: LinearLayout - not vertical or horizontal specified

I was following a tutorial and i noticed that there was a linearlayout that was not specified vertical nor horizontal. I was told in another tutorial that it was basically required... what does it mean to have neither? is it bad? this was enclosed by another linearlayout which DID

<?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" >

    <LinearLayout
        android:id="@+id/group"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add New" 
            android:onClick="onClick"/>

        <Button
            android:id="@+id/delete"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Delete First" 
            android:onClick="onClick"/>

    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

 </LinearLayout>

Upvotes: 10

Views: 14251

Answers (3)

Pang
Pang

Reputation: 10111

When the orientation of a LinearLayout is unspecified, it is using the default, which is horizontal.

According to the official documentation:

android:orientation

Should the layout be a column or a row? Use "horizontal" for a row, "vertical" for a column. The default is horizontal.

It is also mentioned in the Class Overview of LinearLayout:

Class Overview

A Layout that arranges its children in a single column or a single row... The default orientation is horizontal.

And also in setOrientation():

public void setOrientation(int orientation)

...

Parameters

orientation           Pass HORIZONTAL or VERTICAL. Default value is HORIZONTAL.

Upvotes: 6

Visa
Visa

Reputation: 111

default orientation for linearlayout is "horizontal"

Upvotes: 3

K-ballo
K-ballo

Reputation: 81349

It just means that orientation defaults to horizontal. So if the attribute is not there, the linear layout is a horizontal linear layout.

Upvotes: 19

Related Questions