3
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/bag" 
    android:layout_height="fill_parent" android:layout_width="fill_parent"
    android:orientation="vertical" >

<RelativeLayout
        android:id="@+id/relativeLayout2"
            style="@style/relbag"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <TextView style="@style/CodeFont" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="18dp"
        android:textSize="15dp"
        android:text="General Preference"
        android:id="@+id/genpref">
        </TextView>


    <ListView
        android:id="@+id/settingsListView1"
        style="@style/listbag"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dip"
        android:layout_marginRight="15dip"

        android:background="@drawable/radius"
        android:listSelector="@drawable/list_selector"
        android:paddingTop="8dip"
        android:paddingBottom="8dip" 
        android:scrollbars="none"
        android:layout_below="@id/genpref"/>

        <TextView style="@style/CodeFont" 
        android:id="@+id/notpref"
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="25dp"
        android:textSize="15dp"
        android:text="Notification Preference"
        android:layout_below="@id/settingsListView1">
        </TextView>


        <ListView style="@style/listbag" android:id="@+id/settingsListView2" android:layout_width="fill_parent"
         android:layout_height="fill_parent"
            android:layout_marginLeft="15dip" android:layout_marginRight="15dip" 
              android:layout_marginBottom="15dip" 
        android:background="@drawable/radius" 
                android:paddingLeft="5dip" android:paddingRight="5dip" 
            android:paddingTop="15dip" android:paddingBottom="15dip" 
            android:listSelector="@drawable/list_selector" 
            android:layout_below="@id/notpref" 
            android:scrollbars="none"
            />
            </RelativeLayout>
</LinearLayout>

enter image description here

In my app I want create two listview into linearlayout and make linearlayout scrollable not using ScrollView. As far as I read scrollview has a issues working with listview. This picture isn't exactly what I want but let's pretend there is another listview below of listview. So I want display listview's all available items (in my app 2 listview's items) and make LinearLayout scrollable. ScrollView doesn't go fine because it has to have only one direct child. I can't find solution. So please help me make solution, Thanks

fish40
  • 5,738
  • 17
  • 50
  • 69
  • I've seen other questions like this and don't understand why people want to display a `ListView` with all available list items showing. The whole point of a `ListView` (and its ability to scroll) is that it's meant to fit the screen (or part of it) and can be scrolled to show additional items which can't fit the space it occupies. If you want to show a sequence of 'items' just create a view for an item then create multiples of it dynamically inserting them into a `ScrollView` and forget about using `ListView`. – Squonk Nov 29 '11 at 06:30
  • refer http://stackoverflow.com/a/17876855/336990 ...might be useful – CoDe Jul 26 '13 at 08:46

4 Answers4

7

I dont think its a good idea to put multiple lists in a single screen becoz touch will become weird and using screen will become complex.You should think something else to display multiple lists together in a single screen.You can horizontally arrange multiple lists in a single screen.Romain Guy(Google developer) is also accepting this fact in the following link....

http://groups.google.com/group/android-developers/browse_thread/thread/77acd4e54120b777

I hope this answer will help u to solve ur problem.

himanshu
  • 1,990
  • 3
  • 18
  • 36
0

i used this and helped me

ListAdapter listAdapter = listView.getAdapter();
int rows = listAdapter.getCount();
int height = 60 * rows; // Insert the general cell height plus the dividers.

ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = height;
listView.setLayoutParams(params);
listView.requestLayout();

hope help u too

Pirisok
  • 401
  • 3
  • 9
0

Use a LinearLayout as a child to the ScrollView, and place the ListView as a child to the LinearLayout.

SamSPICA
  • 1,366
  • 15
  • 31
  • 2
    That aint gonna work bro, I tried this already. but thanks anyway for your advice – fish40 Nov 29 '11 at 06:24
  • in that case, you can try this question: [Multiple ListView issue](http://stackoverflow.com/questions/306626/scrolling-with-multiple-listviews-for-android) – SamSPICA Nov 29 '11 at 06:28
0

I thnk here is your solution,,

you do not need to use ScrollView in LinearLayout.

Use layout_weight param in childviews (In your case both listview) of your LinearLayout

As layout_weight param is not available in RelativeLayout you need to change it with LinearLayout.

you can make like following,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/bag" 
    android:layout_height="fill_parent" android:layout_width="fill_parent"
    android:orientation="vertical" >

<LinearLayout
        android:id="@+id/relativeLayout2"
            style="@style/relbag"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    android:orientation="vertical">

        <TextView style="@style/CodeFont" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="18dp"
        android:textSize="15dp"
        android:text="General Preference"
        android:id="@+id/genpref">
        </TextView>


    <ListView
        android:id="@+id/settingsListView1"
        style="@style/listbag"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:layout_marginLeft="15dip"
        android:layout_marginRight="15dip"
        android:background="@drawable/radius"
        android:listSelector="@drawable/list_selector"
        android:paddingTop="8dip"
        android:paddingBottom="8dip"/>

        <TextView style="@style/CodeFont" 
        android:id="@+id/notpref"
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="25dp"
        android:textSize="15dp"
        android:text="Notification Preference">
        </TextView>


        <ListView style="@style/listbag" 
        android:id="@+id/settingsListView2" 
        android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
                android:layout_marginLeft="15dip" 
        android:layout_marginRight="15dip" 
                android:layout_marginBottom="15dip" 
            android:background="@drawable/radius" 
                android:paddingLeft="5dip" android:paddingRight="5dip" 
                android:paddingTop="15dip" android:paddingBottom="15dip" 
                android:listSelector="@drawable/list_selector"/>

     </LinearLayout>
</LinearLayout>

Change your xml with above.. i had not tested so their may be some silly error of params that you can solve easily..

Nirav Dangi
  • 3,607
  • 4
  • 49
  • 60