4

enter image description here

I have following scenario:

ImageView, TabHost that has two tabs. Both of these tabs have ListView inside.

What I want to achieve is:

While scrolling up / down in the ListView in the tab - scroll or collapse the ImageView on the top.

Meaning that when I will be scrolling down the ImageView will be disappearing as I will be scrolling down. If I will be scrolling up, ImageView will be appearing again.

I would like to achieve this without using ListView inside a ScrollView (which hasn't produced good results so far).

How would I go about this to achieve it?

Jakub Holovsky
  • 6,543
  • 10
  • 54
  • 98

2 Answers2

0

This is My Example in which I am using Image view and List view in Scroll view You can add your own two Tabs in XML there will be no difference Hope so this will helps.

Layout.xml

 <ScrollView
    android:id="@+id/sv_itemRank"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/img_item_image"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:contentDescription="@string/empty"
            android:scaleType="centerCrop" />

        <ListView
            android:id="@+id/lv_items_lists"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@color/white"
            android:divider="@null"
            android:dividerHeight="0dp"
            android:scrollbars="none" >
        </ListView>
    </LinearLayout>
</ScrollView>

and after populating the listview in my case I am using custom adapter call this function to set Height of List View Based on Children I done this after adapter.notifyDataSetChanged(); you change it respective to your code.

Code for setListViewHeightBasedOnChildren(listview)

pass your listview as parameter.

public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null)
        return;

    int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(),
            MeasureSpec.UNSPECIFIED);
    int totalHeight = 0;
    View view = null;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        view = listAdapter.getView(i, view, listView);
        if (i == 0)
            view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth,
                    LayoutParams.WRAP_CONTENT));

        view.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
        totalHeight += view.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight
            + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}
Joe
  • 6,497
  • 4
  • 29
  • 55
Asad Mehmood
  • 315
  • 1
  • 3
  • 20
0

I know that probably this is not the answer you were looking for, but you can keep the scroolView (and probably you have to).

Try having a look at this post which explains perfectly how to set some listViews inside a scrollView.

I hope it helps :)

EDIT: i found this. It is not exactly the solution you were looking but it uses the onScrollListener and i think that you can adapt this answer to solve your problem, let me know if it works!

Community
  • 1
  • 1
Pier Giorgio Misley
  • 5,305
  • 4
  • 27
  • 66