在滚动网格视图时需要隐藏textView

时间:2014-09-29 10:12:37

标签: android gridview

我在滚动网格视图时尝试隐藏textView,并在用户停止滚动时再次显示相同的textview。 任何人都可以帮我解决这个问题..?

6 个答案:

答案 0 :(得分:0)

实现OnScrollListener,然后在onScroll内部使textView不可见 并在OnScrollStateChanged方法中检查滚动是否停止并使其再次可见

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
    }
};

答案 1 :(得分:0)

你需要set this method on your gridview.它对我有用。我相信它会对你有帮助。

  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    
        }
    });

答案 2 :(得分:0)

试试这段代码:

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);
    }

});

答案 3 :(得分:0)

您可以在setVisibility

中使用OnScrollListener

示例:

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); 
    }
});

希望它有所帮助。

答案 4 :(得分:0)

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); 
}

});

我们在我的应用程序中使用此代码并且它有效,我希望它对您有用。

答案 5 :(得分:0)

试试这个:

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
    }
};