如何使按钮可见/飘在Android的GridView控件的滚动听者 [英] How to Make a Button Visible/Gone on scroll listner of gridView in android

查看:106
本文介绍了如何使按钮可见/飘在Android的GridView控件的滚动听者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的GridView和框架布局的按钮。 code是继

I have a Custom gridView and a Button in Frame Layout. Code is following

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
     <GridView
        android:id="@+id/gridview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/Rel_Spinner"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:numColumns="auto_fit"
        android:stretchMode="columnWidth" >
    </GridView>


    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true" >


        <Button
            android:id="@+id/btnLoadMore"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Load More" />

    </FrameLayout>

</RelativeLayout>

它加载图像和文本的适配器。如图

it loads images and Text from adapter. as shown in figure


  • 现在,我想的是,当达到GridView控件滚动的最终位置其他明智它应该再次消失的按钮应该会出现。如图。

请帮助
在此先感谢

Please Help Thanks in advance

推荐答案

您可以通过使用<一个做到这一点href=\"http://developer.android.com/reference/android/widget/AbsListView.OnScrollListener.html#SCROLL_STATE_IDLE\"相对=nofollow> setOnScrollListener 为GridView控件为:

you can do this by using setOnScrollListener for GridView as:

gridview.setOnScrollListener(new OnScrollListener() {

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

      }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
            // TODO Auto-generated method stub
      switch(scrollState) {
        case 2: // SCROLL_STATE_FLING 
        //hide button here
        break;

        case 1: // SCROLL_STATE_TOUCH_SCROLL 
        //hide button here
        break;

        case 0: // SCROLL_STATE_IDLE 
        //show button here
        break;

            default:
             //show button here
        break;
           }
        }
     });

这篇关于如何使按钮可见/飘在Android的GridView控件的滚动听者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆