2012-10-27 49 views
-2

所以我有这种布局方案,我还没有找到任何理想的解决方案。我已经画了一个,我希望这是可以理解的。ListView + textview下面的布局问题

enter image description here

现在我的ListView始终处于底部的LinearLayout以上。当ListView有几个项目时,TextView就在下面,看起来很好。但是,当它有很多项目时,它会压碎TextView,它们之间应始终存在,无论在LW和底部容器之间。

任何人都可以给我一个XML例子,实现这一目标吗?

回答

1

您可以包装ListViewLinearLayout并设置权重来此Linearlayout,该TextView和底部LinearLayout。 (您必须将ListView包装在LinearLayout内,因为您无法将权重应用于ListView)。

+0

这工作得很好。我正在使用一个相对布局作为根,这给我的问题 –

-1

如果我不想错过,请尝试创建一个ListView,例如wrap_content?而TextView总是低于ListView?如果我没有错,那么,这就是你需要:以上

<LinearLayout // Your list view and TextView in a same linear layout 
    android:layout_alignParentTop="true" 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" // With this specific height, your TextView will 
            // always in this range! 
    android:orientation="vertical" > 

    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" > 
    </ListView> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:layout_marginBottom="91dp" 
     //layout_gravity = "right"?? I'm not sure, you should make it right alignment 
    /> 
</LinearLayout> 

<LinearLayout /> // This is your linear layout at the Bottom, 2 Lineary layout is 
       // putted in a Relative layout 

布局给你一个ListView在顶部,而TextView的是下面的的LinearLayout在底部。试试看!!

+1

你**不能**限制ListView的高度。您必须将其包装在LinearLayout中。 – Ahmad

+0

@Ahmad:是啊!我知道,但对我来说,上面的代码运行良好!你有试过吗? –