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>
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.
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" .
android:orientation Use "horizontal" for a row, "vertical" for a column. The default is horizontal.
LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally.
It just means that orientation
defaults to horizontal
. So if the attribute is not there, the linear layout is a horizontal linear layout.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With