Hello-World
Hello-World

Reputation: 9545

LinearLayout's next to each other

Im trying to have two LinearLayout's next to each other but the below code wont work , it puts them so that one is on top.

can you please help. or do you have a better idea?

thanks?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" 
    android:layout_weight="0.5"
    android:background="#999"> 



</LinearLayout>

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" 
android:layout_weight="0.5"
    android:background="#977000"> 



</LinearLayout>



</LinearLayout>

Upvotes: 1

Views: 2731

Answers (7)

user3081695
user3081695

Reputation: 55

Set orientation of outer linear layout as "horizontal".. it works

Upvotes: 2

NagarjunaReddy
NagarjunaReddy

Reputation: 8645

use this just change android:orientation="horizontal" in place of android:orientation="vertical

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:background="#999"
    android:orientation="horizontal" >
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:background="#977000"
    android:orientation="horizontal" >
</LinearLayout>

Upvotes: 4

user543
user543

Reputation: 3633

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout 
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal" 
android:layout_weight="1"
android:background="#999"> 
</LinearLayout>
<LinearLayout 
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal" 
android:layout_weight="1"
android:background="#977000"> 
</LinearLayout>
</LinearLayout>

Upvotes: 1

Ben Weiss
Ben Weiss

Reputation: 17922

Replace android:orientation="vertical" with android:orientation="horizontal" in your top LinearLayout.

Upvotes: 2

Nathua
Nathua

Reputation: 8826

android:orientation="horizontal"

Upvotes: 1

Phant&#244;maxx
Phant&#244;maxx

Reputation: 38098

This

android:orientation="vertical" >

has to be

android:orientation="horizontal" >

In your outer LinearLayout

Upvotes: 1

Sebastien FERRAND
Sebastien FERRAND

Reputation: 2150

Try to set your first linearLayout at "horizontal", not "vertical"

Upvotes: 1

Related Questions