Any way to use a list or grid views in a scrollview in xamarin android?

ozkaro 66 Reputation points
2021-04-11T03:17:58.823+00:00

good day
I was looking for any answer or alternative to use a listview inside a layout inside what is in a scrollview, even I disabled the listview but the scroll in the scrollview doesn't works and I can't find nothing helpful.
I want to ask if there is another way to show a collection with controls as buttons, labels or replace the listview with a similar vehaviour without scroll, or in NUGET package library exists a similar control?
I come developing from windows 8 mobile now I'm working with xamarin android (no forms)

anyway thanks in advance

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. JessieZhang-MSFT 7,716 Reputation points Microsoft External Staff
    2021-04-12T06:19:41.613+00:00

    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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.