0

我有一个带有LinearLayout的Linear.xml,包含LinearLayout,ListView和LinearLayout中的三个项目。我希望ListView尽可能大,同时保持底部的LinearLayout始终显示,而不是缩小或关闭屏幕。获取视图以适合

我已经尝试使ListView高度fillparent,但然后底部LinearLayout不显示,与wrapcontent相同,因为ListView有很多内容。

当我使ListView成为设置大小,比如300dp时,我在底部的LinearLayout下面有空间。我试图通过使顶层LinearLayout gravity = fill来解决这个问题,但这并没有帮助。

此外,根据android我尝试它,底部的LinearLayout将从屏幕上退出或收缩。 如果相关,顶层LinearLayout被设置为fillparent以指示高度。 我的目标是保持顶部和底部的LinearLayout包装他们的内容,并且中间的ListView填充剩下的东西...任何建议? 在此先感谢您的努力!

回答

3

我相信你可以直接将android:layout_weight="1"添加到ListView中,将ListView设置为fill_parent的高度,并将两个LinearLayouts设置为wrap_content。无论如何,我通常更喜欢使用RelativeLayout。您可以指定头对准屏幕的顶部,页脚对齐底部,ListView控件,以填补空间之间,像这样:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <LinearLayout 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     > 
     //...insert stuff here 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/footer" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     > 
     //...insert stuff here 
    </LinearLayout> 

    <ListView 
     android:id="@+id/listview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/footer" 
     android:layout_below="@id/header" 
     /> 
</RelativeLayout> 
+0

感谢两种反应是完美的!并且,学习新视图很好 – 2011-03-01 06:45:05