2012-10-17 82 views
1

现在它垂直分割......我希望它水平分割。我看其他人,说他们的削减水平和我不能告诉区别...如何在屏幕上水平分割屏幕

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

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="top" 
    android:layout_weight="1" > 
</LinearLayout> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="bottom" 
    android:layout_weight="1" > 
</LinearLayout> 

</LinearLayout> 

回答

3

您的方向改为vertical

<?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:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:layout_gravity="top" 
android:layout_weight=".1" > 
</LinearLayout> 

<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:layout_gravity="bottom" 
android:layout_weight=".1" > 
</LinearLayout> 

</LinearLayout> 
+0

为什么改变方向垂直做到这一点...? – cj1098

+0

您想将画面分成一个线性向下,因此可以将方向设置为垂直 –

0

这应该工作。

<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="0dip" 
    android:layout_height="match_parent" 
    android:layout_gravity="top" 
    android:layout_weight="1" > 
</LinearLayout> 

<LinearLayout 
    android:layout_width="0dip" 
    android:layout_height="match_parent" 
    android:layout_gravity="bottom" 
    android:layout_weight="1" > 
</LinearLayout> 

</LinearLayout> 
+0

此代码不会改变。将父线性布局的方向更改为垂直 –

+0

@Ramkiran,该问题的作者想要水平分割屏幕,请仔细阅读该问题。 – Egor

1

你应该让子视图`FILL_PARENT

<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:orientation="horizontal" 
    android:weightSum="2" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 
    </LinearLayout> 

</LinearLayout> 

这会并排创建2升LinearLayout对象侧。

,如果你想创建ontop的其他的一个,你应该做的,而不是android:orientation="vertical"