Set orientation in LinearLayout in android using xml

How to add android:orientation=”vertical” and android:orientation=”horizontal” inside linear layout.

Orientation tells the app compiler that your application has vertical widget support or horizontal widget support. Normally portrait android mobile devices supports vertical orientation and devices like Tablets, TVs application look smooth in horizontal orientation. LinearLayout cannot work without setting up orientation. So here is the complete step by step tutorial for Set orientation in LinearLayout in android using xml.

android-project-download-code-button

How to Set orientation in LinearLayout in android using xml.

Code for MainActivity.java file.

package com.setorientation_android_examples.com;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.setorientation_android_examples.com.MainActivity"
 android:orientation="vertical" >

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Sample Text 1"
 android:textAppearance="?android:attr/textAppearanceLarge" />
 
 <TextView
 android:id="@+id/textView2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Sample Text 2"
 android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

Screenshot:

Set orientation in LinearLayout in android using xml

Click here to download Set orientation in LinearLayout in android using xml project.

Leave a Reply

Your email address will not be published. Required fields are marked *