Android ListView列表上下滑動趨勢方向測算

原文:https://blog.csdn.net/uyy203/article/details/78925559

    private class JudgeScrollType implements AbsListView.OnScrollListener
    {
        private int trendY = 0;
        private int TotalTrendY = 0;
        private int lastTop = 0;
        private int top = 0;
        private int lastTag = 0;
        private int count = 0;
        private int maxCount = 5;
        private int duration = 300;

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



                    if(view.getChildAt(0).getTop() == 0 || firstVisibleItem != lastTag)
                    {
                        top = 0;
                        lastTop = 0;
                        trendY = 0;
                    }
                    else
                    {
                        top = -view.getChildAt(0).getTop();
                    }

                    trendY = top - lastTop;
                    lastTop = top;
                    lastTag = firstVisibleItem;


                    //數(shù)據(jù)降噪
                    if(top == trendY)
                    {
                        trendY = 0;
                    }

                    //取5個趨勢值,然后取均值,利用均值作為判斷趨勢值
                    if(count < maxCount)
                    {
                        TotalTrendY += trendY;
                        count++;
                    }
                    else
                    {
                        trendY = TotalTrendY / count;
//                      count = 0;
                        TotalTrendY = 0;
                    }

                    if((count >= maxCount && trendY < 0) )
                    {

                    /**列表下滑時對應(yīng)操作**/

                    }
                    else if(count >= maxCount && trendY > 0 )

                    /**列表上滑時對應(yīng)操作**/

                    }

                    if(count >= maxCount)
                    {
                        count = 0;
                    }






        }

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

        }
    }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容