2013-03-18 48 views
0

我有两种布局。其实5,3垂直一个在另一个之下,在中间一个我有2个并排布局。我需要他们是固定的大小,所以他们会改变。但是,只要我按下其中一个按钮,它们就会改变大小,如下图所示。如何让他们不变?无论如何,这是我的代码和图片。如何制作固定的XML布局?

Layout One Layout Two

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="20" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_weight="3" > 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="15" 
     android:orientation="horizontal" > 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:layout_weight="1" > 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:layout_weight="1" > 
     </LinearLayout> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_weight="2" > 
    </LinearLayout> 

</LinearLayout> 

回答

1

尝试改变两个内布局,以这样的:

选项#1:这将水平固定的布局,不垂直

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:layout_weight="50" > 
</LinearLayout> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:layout_weight="50" > 
</LinearLayout> 

选项#2:这将修复双向布局

使用LinearLayouts的嵌套权重效率非常低。相反,请将您的根视图更改为RelativeLayout并摆脱权重。 请注意,这不是一个100%的完整的解决方案,但它一定会得到你开始。这将使第一LinearLayout在布局的顶部,并在布局底部的最后LinearLayout。中间的一个将始终在顶部视图下方并在底部视图下方。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout android:id="@+id/top" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:orientation="vertical"> 
    </LinearLayout> 

    <LinearLayout android:id="@+id/middle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/top" 
     android:layout_above="@+id/bottom" 
     android:orientation="horizontal" > 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:layout_weight="1" > 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 
     </LinearLayout> 

    </LinearLayout> 

    <LinearLayout android:id="@+id/bottom" 
     android:layout_alignParentBottom="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 
    </LinearLayout> 
</RelativeLayout> 
+0

这工作了水平移动,它是固定的,但它还是挺大的verticaly。 – user2083882 2013-03-18 14:39:03

+0

查看编辑,我添加了第二个选项 – Sababado 2013-03-18 15:13:57

0

尝试将layout_weight更改为中间线性布局的子线性布局的0.5。