开发者

How to show another layout in listactivity

开发者 https://www.devze.com 2023-02-08 17:12 出处:网络
I have a listactivity which contains a listview. i want to show another layout which contains a button at top and a webview at bottom on this listview and that layout always to be shown. I tried this

I have a listactivity which contains a listview. i want to show another layout which contains a button at top and a webview at bottom on this listview and that layout always to be shown. I tried this but this is not what i want to do :

ListView lv =getListView();
LayoutInflater inflater = getLayoutInflater();
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.mylayer, lv, false);
lv.addHeaderView(he开发者_Go百科ader, null, false);

This shows my layout but when i scroll my listview, needless to say that when i scroll my listview down it is no more to be shown like it is part of my other listview items.


When using ListActivity, you can use any layout you want. The only contract you must follow is putting a ListView whose id is list. Thus, you can do something like:

<?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>

If you do want to reuse another layout, change the TextView for something like <include> (take a look at this article).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号