ListView + textview下面的布局问题

时间:2012-10-27 00:16:49

标签: android android-layout

所以我有这个布局方案,我没有找到任何理想的解决方案。我已经画了它,我希望这是可以理解的。

enter image description here

现在我的ListView始终位于底部的LinearLayout之上。当ListView只有很少的项目时,TextView就在下面,它看起来很好。然而,当它有许多项目时,它会破坏两者之间的TextView,无论如何,它应始终存在于LW和底部容器之间。

有人能给我一个xml例子来实现这个吗?

2 个答案:

答案 0 :(得分:1)

您可以将ListView打包到LinearLayout内,并将权重设置为此LinearlayoutTextView和底部LinearLayout。 (您必须将ListView包装在LinearLayout中,因为您无法对ListView应用权重。

答案 1 :(得分:-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在下面,在Bottom的LinearLayout。试试看!!