I am trying to build a listview with a header row anchored to the top of the listview and scrolls with the listview. I know I’m not supposed to embed a listview within a scrollableview, but how else can I achieve this effect. I want it to look like the News Feeds screen on the stock Facebook app for Android where the “What’s on your mind…” EditText scrolls away when you scroll down to read the feeds.
My pseudo-code looks like this which works but when I launch the app, it always scrolls down a bit hiding the button until I touch-scroll back up:
<ScrollView>
<LinearLayout orientation="vertical">
<Button />
<ListView />
</LinearLayout>
</ScrollView>
Rather than doing it through XML, and trying to wrap it in a
ScrollView, you can use ListView’saddHeaderView()method to add your custom View to the list prior to callingsetAdapter().