简体   繁体   中英

Need to hide a textView while scrolling a grid view

I'm trying to hide a textView while scrolling a grid view and make the same textview visible again when the user stops scrolling. Can anyone help me fixing this issue..?

implement OnScrollListener and then inside the onScroll make the textView invisible and in the OnScrollStateChanged method check if the scroll stopped and make it visibile again

private OnScrollListener mScrollListener = new OnScrollListener() {

    @Override
    public void onScrollStateChanged(ViewGroup view, int scrollState) {
         if(scrollState == SCROLL_STATE_IDLE)
         {
                 textView.setVisibility = View.VISIBLE;       
         }

    @Override
    public void onScroll(ViewGroup view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                 textView.setVisibility = View.INVISIBLE
    }
};

You need to set this method on your gridview. it works for me. I am sure it will help you.

  gridAdmin.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

            if(scrollState == SCROLL_STATE_IDLE)
             {
                     text1.setVisibility = View.VISIBLE;   
             }

        }

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

             text1.setVisibility = View.INVISIBLE    
        }
    });

Try this code:

private OnScrollListener mScrollListener = new OnScrollListener() {

    @Override
    public void onScrollStateChanged(ViewGroup view, int scrollState) {
        if(scrollState == SCROLL_STATE_IDLE)
        {
            tv.setVisibility(View.VISIBLE);
        }
    }
    @Override
    public void onScroll(ViewGroup view, int firstVisibleItem, int visibleItemCount, int totalount)
    {
        tv.setVisibility(View.INVISIBLE);
    }

});

You can use setVisibility in OnScrollListener

Example:

gridview.setOnScrollListener(new OnScrollListener() {
    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {

        if(scrollState == SCROLL_STATE_IDLE)
        {
            textview.setVisibility(View.VISIBLE);   
        }
    }

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

        textview.setVisibility(View.GONE); 
    }
});

Hope it helps.

gridView.setOnScrollListener(new OnScrollListener() {

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {

    if(scrollState == SCROLL_STATE_IDLE)
    {
        textview.setVisibility(View.VISIBLE);   
    }
}

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

    textview.setVisibility(View.GONE); 
}

});

We use this code in my app and it work , I hope it will useful to you.

Try this:

Private OnScrollListener mScrollListener = new OnScrollListener() {

@Override
    public void onScrollStateChanged(ViewGroup view, int scrollState) {
         if(scrollState == SCROLL_STATE_IDLE)
     {
                 mTextView.setVisibility = View.VISIBLE;       
         }
@Override
    public void onScroll(ViewGroup view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                 mTextView.setVisibility = View.INVISIBLE
    }
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM