滚动列表视图时,视图应隐藏

时间:2014-05-14 05:00:28

标签: android android-listview

嗨我在滚动列表视图时遇到了隐藏相对布局的问题。

必需:

当我滚动列表视图时,相对布局应该是不可见的

当我没有滚动时,相对布局应该是可见的

Function.java

lv.setOnScrollListener(new OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState)
            {
                // TODO Auto-generated method stub
//              rel.setVisibility(View.GONE);


            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount)
            {

                rel.setVisibility(View.INVISIBLE);

                if(firstVisibleItem == 0)
                {

                }
                else
                {
                    rel.setVisibility(View.VISIBLE);
                }

            }
        });

mylayout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="#b5b5b5"
        android:dividerHeight="1dp" />

    <LinearLayout
        android:id="@+id/myrelative"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#FF0000"
        android:orientation="horizontal"
         >

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>

</RelativeLayout>

请指导我解决这个问题

1 个答案:

答案 0 :(得分:1)

试试这个

private int mLastFirstVisibleItem;
    private OnScrollListener lead_scrolllist = new OnScrollListener()
        {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) 
            {
                if (view.getId() == LeadDetail_listview.getId()) 
                {
                    final int currentFirstVisibleItem = LeadDetail_listview.getFirstVisiblePosition();

                    if (currentFirstVisibleItem > mLastFirstVisibleItem) 
                    {
                        Linear_leadfooter.setVisibility(View.GONE);
                    } 
                    else if (currentFirstVisibleItem < mLastFirstVisibleItem) 
                    {

                        Linear_leadfooter.setVisibility(View.VISIBLE);
                    }

                    mLastFirstVisibleItem = currentFirstVisibleItem;
                } 
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem,
                    int visibleItemCount, int totalItemCount) 
            {

            }
        };