Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView inside scroll view magic

For my app I want to enable a thing looking somehow like this:

<ScrollView>
    <LinearLayout orientation="vertical">
        <FrameLayout layout_height="48dp">
            Anything I want here...
        </FrameLayout>
        <ListView>
            It's size will be set to screen height anyway
        </ListView>
    </LinearLayout>
</ScrollView>

And I want to do so, that when user touches the screen to scroll, at first only scrollview scrolls, and then, when it reaches one of its edges the scroll event goes to listview and it begans scrolling.

How can I achieve that?

P.S. the reason for this is to make some kind of hiding actionbar, which scrolls off the screen when user goes deeper down, and then as he scrolls up it should appear from bottom not with an animation but as the list is moved. so if i scrolled the list half the height of the actionbar - i see the bottom half of the actionbar on the screen. You can see what I mean in iOS Google+ app.

Any help will be appreciated.

like image 602
Graykos Avatar asked Dec 07 '25 06:12

Graykos


1 Answers

in Layaout set Parameter

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true" >

      <ListView
                    android:id="@+id/listview"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">
      </ListView>
</ScrollView>

And in the Coding Part Set the Dynamic height of listview according to device height

    LayoutParams lp = (LayoutParams) list1.getLayoutParams();
    int height = (arraylist.size()) * 80; 

        //arraylist list is in which all data is kept

    lp.height = height;
    listview.setLayoutParams(lp);

    listview.setAdapter(Adapter);
like image 77
Anshul Avatar answered Dec 08 '25 19:12

Anshul