Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: LinearLayout - not vertical or horizontal specified

Tags:

android

layout

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>
like image 948
Brandon Ling Avatar asked Jun 20 '12 17:06

Brandon Ling


People also ask

What is the default orientation for a LinearLayout?

By default, orientation is horizontal. Horizontal orientation will only have one single row of elements on the screen and in the case of vertical orientation, it will only have one child per row. One more important attribute in a linear layout is the android:layout_weight attribute which assigns weights to elements.

How do you create a LinearLayout vertical?

To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .

What is the default value of orientation attribute in LinearLayout?

android:orientation Use "horizontal" for a row, "vertical" for a column. The default is horizontal.

What is the android layout that arranges the contents horizontally or vertically?

LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally.


2 Answers

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

like image 74
K-ballo Avatar answered Sep 17 '22 13:09

K-ballo


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.

like image 21
Pang Avatar answered Sep 17 '22 13:09

Pang