2012-08-11 106 views
0

我想创建一个具有两个LinearLayout(vertcal位置)的布局。Android百分比布局

首先linearLayout有80%从空间和另外20%(我用weightSum = 10)。

在第二个布局上,我有一个文本输入,当键盘出现时,屏幕尺寸缩小了,所以第二个线性布局太小了。

我希望我的secondLayout有最小的100dp和第一个布局,剩下的但我不知道如何实现这个。

谢谢!

Print screen

+0

使用支持库,您现在可以使用PercentRelativeLayout和PercentFrameLayout:https://juliengenoud.github.io/android-percent-support-lib-sample/ – 2015-08-03 16:46:14

回答

2

重量被用于分发的剩余空的空间或带走空间,当总和大于所述的LinearLayout大。将你的宽度设置为0dip,它会起作用。

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:weightSum:"10" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="0dip" 
     android:layout_weight="8" > 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="0dip" 
     android:layout_weight="2"> 
    </LinearLayout> 

</LinearLayout> 
+0

这是我做的,但是在这种情况下,问题是,当方向是横向或键盘出现时,第二个布局变得太小。我希望我的第二个布局具有200dp的高度,第一个布局可以获得剩余的空间。 – Catalin 2012-08-12 12:44:54

+0

你可以创建Layout-land文件夹并在横向上创建你的xml。 – Basbous 2012-08-12 13:29:14

+0

这是真的,但当键盘出现时,我该怎么办? – Catalin 2012-08-12 14:00:12