2014-01-21 57 views
1

我试着让两个LinearLayout彼此相邻,但下面的代码不会工作,它将它们放在最前面。LinearLayout彼此相邻

你能否请帮忙。或者你有更好的主意?

谢谢?

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

回答

1

尝试在 “水平”,而不是 “垂直”

1

设置你的第一个的LinearLayout这

android:orientation="vertical" > 

必须

android:orientation="horizontal" > 

在你的外在的LinearLayout

1
android:orientation="horizontal" 
2

android:orientation="vertical"替换为android:orientation="horizontal"在您的顶部LinearLayout

1
<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> 
4

使用这只是改变android:orientation="horizontal"代替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> 

2

外线性布局的设定方向为 “水平” ..它的工作原理