2010-11-22 89 views
3

我想分我的屏幕分为两个部分,我有一个LinearLayout并再次将其包含两个LinearLayoutsAndroid的布局分割

如何划分这两个LinearLayouts分成相等的两部分?

+0

刚刚看了您的回复答案。让我知道..你想如何划分他们?垂直(堆叠在彼此的顶部)或水平(出现在彼此的侧面)? – kishu27 2012-03-23 12:20:13

回答

8

只需添加:

android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_weight="1" 

他们两个。相等的layout_weight参数均匀分配空间量。

上接受一些答案到你前面的问题,以及工作。

+0

HI感谢您的解决方案,但我不能让两个布局划分,我已经硬编码了layout_width价值为200px,我不想做这样的,请建议用例子 – ramsbh 2010-11-22 07:38:17

+0

这是你怎么做。如果你想硬编码你的宽度,那么它当然不会缩放到50%。将其更改为fill_parent。 – kcoppock 2010-11-22 13:38:19

0

检查这个例子可以帮助你。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    android:id="@+id/rootlinearlayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <LinearLayout 
     android:id="@+id/linearlayout01" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:orientation="vertical"> 
     <EditText 
      android:id="@+id/et01" 
      android:gravity="center" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="First TextBox" 
      android:textSize="18sp" /> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/linearlayout02" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:orientation="vertical"> 
     <EditText 
      android:id="@+id/et02" 
      android:gravity="center" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Another TextBox" 
      android:textSize="18sp" /> 
    </LinearLayout> 
</LinearLayout> 
+0

嗨,感谢您的答复,我想分成垂直的两个画面,我用你的代码中,“AnotherTextbox”是“第一个文本框”后非常快到了,我想50%的第一和50 %到second.Any建议? – ramsbh 2010-11-22 08:54:27

+0

在两个EditText中尝试android:layout_height =“match_parent”。这应该很好。 – 2010-11-22 09:17:42

1

正常情况下,我使用android:layout_weight =“1”。你也可以使用表格布局。

0

我们可以使用 android:layout_width="0dp"android:layout_weight="1"两个片段 的和这些家长,我们可以使用android:layout_width="fill_parent"