0

I want to use multiple ListView/GridView within same User Interface; I don't want them to be expanded to their full length and placed under ScrollView.

TN888
  • 7,659
  • 9
  • 48
  • 84

4 Answers4

0

If you want to learn about ListView, here is a nice tutorial. About your question, here is the similar one! Your question might even be duplicate of this.

Community
  • 1
  • 1
0

I don't think that putting multiple ListView/GridView objects inside ScrollView is a good idea.

The biggest advantage of ListView/GridView is that they reuse View's. When you scroll a ListView what the system really does is to use fixed number of views, and swaps the view settings (text, image source etc.). This is done by requesting the getView(int,View,ViewGroup) method from the list Adapter.

What you are trying to do is to force the ListView/GridView to render all it's raws, which pretty much beats the whole purpose of using ListView/GridView in the first place.

Use LinearLayout inside the ScrollView instead, and then add Views dynamically from your Activity/Fragment

aldorain
  • 790
  • 5
  • 16
0

Just specify dimensions to your ListView/GridView that are not all match_parent.

Also, if you want to proportionally allocate say 50% and 50% of available height to your list and grid, put them in a LinearLayout and use the layout_weight mechanism:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ListView
         android:layout_width="match_parent"
         android:layout_height="0px"
         android:layout_weight="1"
         ... />

    <GridView
         android:layout_width="match_parent"
         android:layout_height="0px"
         android:layout_weight="1"
         ... />

</LinearLayout>
laalto
  • 150,114
  • 66
  • 286
  • 303
0

you can set the layout to include how many listViews and gridViews as you wish. just choose a layout and set their sizes yourself. if you put them in a linearLayout, you can set a weight for each of them, to make their width/height proportional to the layout width/height.

However, do note that the more you put, the more cluttered the UI is.

Also note that Google suggests to never put listViews and gridViews inside ScrollViews (this was being talked about on the "the world of listView" lecture) .

android developer
  • 114,585
  • 152
  • 739
  • 1,270