Hello,
Welcome to our Microsoft Q&A platform!
Any way to use a list or grid views in a scrollview in xamarin android?
Do you want to add some other controls with controls as buttons, labels above or below a listView? If yes, you can use a Header View
or/and Footer View
on the list itself. Don't mix a ScrollView
with a ListView
or anything that can scroll. It's meant to be used with headers and footers.
You can put all the content above your ListView, put it in another .xml
file(e.g. header.xml) as a layout , after that you can inflate it and add it to the list as a header view.
You can refer to the following code:
listview = FindViewById<ListView>(Resource.Id.mListview);
string[] countries = Resources.GetStringArray(Resource.Array.countries_array);
adapter = new ArrayAdapter<string>(this, Resource.Layout.list_item, countries);
LayoutInflater mInflater = (LayoutInflater)this.GetSystemService(LayoutInflaterService);
View header = mInflater.Inflate(Resource.Layout.header, listview, false);
View footer = mInflater.Inflate(Resource.Layout.footer, listview, false);
//add a header
listview.AddHeaderView(header, null, false);
//add a footer
listview.AddFooterView(footer,null,false);
listview.Adapter = adapter;
Note: header
and footer
are layout files that represent the header and the footer , respectively.
Best Regards,
Jessie Zhang
---
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.