Search code examples
androidandroid-layoutandroid-listviewandroid-listfragmentandroid-scrollview

ListFragment inside a ScrollView Android


Here is my current layout:

<RelativeLayout>
    <ListFragment/>
</RelativeLayout>

I want to add a picture just before the fragment, something like this:

<ScrollView>
    <RelativeLayout>
        <ImageView/>
        <ListFragment/>
    </RelativeLayout>
</ScrollView>

But, ListFragment use a ListView, and I want the picture to moves with the ListView. It must work if we replace the ListView by a LinearLayout, but how can I use a ListFragment with a LinearLayout instead? Or at least, how can I use a LinearLayout as a List?

Thanks.


Solution

  • Instead of doing such a horrible thing like putting a ListView inside a ScrollView (you will confuse Android's scroll manager), just use the addHeaderView() method of the ListView, to put a View before all the items.

    The so added "header" will scroll away with the items.