Search code examples
androidlistviewandroid-listviewandroid-scrollview

Android ListView not scaling properly


I am new to android programming and I came across a problem I can not solve. I googled it for a while but did not find the sollution to my scenario. Far as I understand ListViews in android are adopting their size based on the space on the screen, but what if I need more space.

I have a layout like below on picture and problem is that second ListView is only one item big and then you need to scroll, but I want it to be at least few (visible - non scroll) items. I do not want it to make fixed height. But even if I do then still it goes out of the visible area, which forces me to make a ScrollView which again does not work with ListViews.

So I am quite lost. Please for guidance

enter image description here


Solution

  • You could put both listviews with weights into a LinearLayout. See second picture: http://android4beginners.com/wp-content/uploads/2013/07/android_studio_linear_layout_example.png

    All you need to do is set the weights of the listviews according to the design you were looking for.

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/main_rel"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:weightSum="2.0" >
    
        <ListView
            android:id="@+id/child_one"
            android:layout_width="match_parent"
            android:layout_height="0"
            android:layout_weight="1.0"
            android:background="#0000FF" >
        </ListView>
    
        <ListView
            android:id="@+id/child_two"
            android:layout_width="match_parent"
            android:layout_height="0"
            android:layout_weight="1.0"
            android:background="#00FF00" >
        </ListView>
    
    </LinearLayout>