1

I am trying to get the vertical scroll for a list view but all the time all the list view items are being shown even if this means that they will get out of the phone's display.

This sis the code I have been using:

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px">
<GridLayout
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:rowCount="6"
    android:columnCount="1"
    android:orientation="vertical"
    android:id="@+id/myGridID">

    <!-- other controls like TextView, EditBox, other Grid layouts -->

    <ListView
         android:layout_row="4"
         android:layout_column="0"
         android:isScrollContainer="true"
         android:choiceMode="singleChoice"
         android:scrollbarSize="100px"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:id="@+id/myListId" />

    <!-- other controls like TextView, EditBox, other Grid layouts -->

</GridLayout>
</LinearLayout> 

I expected that when the height of the list's items will be more than 100px (a value bigger than the value from android:scrollbarSize) the vertical scroll will become active. This is not happening.

Using the below code:

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px">
<GridLayout
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:rowCount="6"
    android:columnCount="1"
    android:orientation="vertical"
    android:id="@+id/myGridID">

    <!-- other controls like TextView, EditBox, other Grid layouts -->

    <ScrollView 
      a:visibility="visible"
      xmlns:a="http://schemas.android.com/tools"
      android:scrollbars="vertical"
      android:visibility="visible"
      android:layout_height="150px"
      android:layout_row="4"
      android:layout_column="0">
        <ListView
          android:isScrollContainer="true"
          android:choiceMode="singleChoice"
          android:scrollbarSize="100px"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:id="@+id/myListId" />
    </ScrollView>

    <!-- other controls like TextView, EditBox, other Grid layouts -->

</GridLayout>
</LinearLayout>

So having the list view put inside a ScrollView was creating a vertical scroll, but all the time only one list item was shown, so also here I was expected to see at least three items from the list view and then to scroll through the rest of the items.

Still I prefer to add the vertical scrolling feature to my app by using only the list view if possible, since the ScrollView seems to complicate things when trying to get a child from the list.

Could someone please explain me what I am doing wrong for the build in vertical scroll of the android xamarin list view ?

Clock
  • 824
  • 1
  • 14
  • 31
  • Possible duplicate of [ListView inside ScrollView is not scrolling on Android](https://stackoverflow.com/questions/6210895/listview-inside-scrollview-is-not-scrolling-on-android) – FreakyAli Jan 01 '19 at 19:50
  • I read the suggested possible duplicate and I consider that my question is something else because I try to avoid adding the list view inside a ScrollView. I better try to add the build in vertical scroll of the list view. And one more difference may come that I try to achieve this by using Android Xamarin and not native Java code and if possible by using just xml designer code. – Clock Jan 01 '19 at 19:59
  • there is no difference between native Android and xamarin android when it comes to XML – FreakyAli Jan 02 '19 at 06:46

1 Answers1

2

Listview by default has a Scroll, adding scrollview as a parent to it is a bad practice,

For a better understanding of how things work check the following post here

UPDATE

Remove the scroll and change the listview code as follows:

  <ListView
    android:layout_width="match_parent"
    android:divider="#D3D3D3" //divider color 
    android:dividerHeight="1dip" // Height
    android:layout_height="wrap_content"
    android:id="@+id/myListId" 
    />

In case you need the below properties too, add them one by one and see if changing these is causing any issues.

      android:isScrollContainer="true"
      android:choiceMode="singleChoice"
      android:scrollbarSize="100px"
FreakyAli
  • 9,662
  • 3
  • 16
  • 45
  • Thank you for your answer ! I also consider that the build in scroll of the list view should work and should be used, still I could not see it. The only way I could add the vertical scroll was to put the list view inside a scroll view. – Clock Jan 01 '19 at 20:01
  • Actually, I would suggest you change the listview code in XML like i am posting above and remove the scroll view and check if it works for you – FreakyAli Jan 02 '19 at 06:48
  • I tried using your code sample and for me the scroll did not appear. Did you had the same parent layouts like GridLayout and then LinearLayout for your list view when you tried ? – Clock Jan 02 '19 at 09:07
  • Correct me if i am wrong but are you trying to add a scrollbar to the right hand side of your list to help with scrolling or is your listview not scrolling properly – FreakyAli Jan 02 '19 at 09:17
  • I am trying the first thing that you said, so I need a vertical scroll bar that usually occurs to the right side of the list in case that the list view does not have enough "height" to directly show all the items from the list. – Clock Jan 02 '19 at 13:50
  • add `android:scrollbars="vertical"` to your listview XML and see if the scrollbar is visible – FreakyAli Jan 02 '19 at 13:52
  • I added it but no scroll was being shown. The list view shows only the first 3 items from it, and I have something like 7 items into the list view, – Clock Jan 02 '19 at 14:00
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/186051/discussion-between-g-hakim-and-clock). – FreakyAli Jan 02 '19 at 14:03
  • After we discussed in chat, @G.hakim suggested me to remove the GridLayout parent of my List view, after doing that the scroll worked as expected for the list view. Thank you a lot for help ! – Clock Jan 02 '19 at 17:32