2011-02-02 40 views
1

我有一个listactivity包含一个列表视图。我想显示另一个布局,其中包含顶部的按钮和此列表视图底部的webview,并且总是显示布局。我试过,但这个不是我想做的事:如何在列表中显示另一个布局

ListView lv =getListView(); 
LayoutInflater inflater = getLayoutInflater(); 
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.mylayer, lv, false); 
lv.addHeaderView(header, null, false); 

这说明我的布局,但是当我滚动我的列表视图,不用说,当我滚动我的列表视图下它已不再是要显示喜欢它是我的其他listview项目的一部分。

回答

3

使用ListActivity时,您可以使用任何您想要的布局。您必须遵循的唯一合同是放置一个ListView,其编号为list。因此,你可以这样做:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<TextView 
    android:id="@+id/something" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:text="What ever"/> 
<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_above="@+id/something"/> 
</RelativeLayout> 

如果你想重新使用另一种布局,改变TextView这样的事情<include>(看看this article)。

相关问题