简体   繁体   English

如何停止列表视图上的滚动动画?

[英]How can I stop the scrolling animation on a listview?

Is it possible to stop a ListView from scrolling? 是否可以阻止ListView滚动? I currently have a ListView with a margin on top to show an image view that will sit behind there. 我目前有一个ListView ,顶部有一个边距,以显示一个位于其后的图像视图。 My goal is to cover the ImageView that will sit behind the ListView when the person is scrolling up, as the ListView is scrolls up it will also close the margin it has eventually hiding the ImageView that sits behind it. 我的目标是覆盖当人员向上滚动时将位于ListView后面的ImageView ,因为ListView向上滚动也将关闭其最终隐藏位于其后的ImageView的页边距。 I currently have it doing just that but I'm trying to figure out how to stop the scrolling animation on the ListView till the ListView closes it's margin. 我目前正在这样做,但是我试图弄清楚如何停止ListView上的滚动动画,直到ListView关闭其空白为止。 ('mainItemDisplayer' is the ListView .) (“ mainItemDisplayer”是ListView 。)

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

            //mainItemDisplayer.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_CANCEL, 0, 0, 0));
            int scrolledOffset = mainItemDisplayer.getVerticalScrollOffset();

            if (scrolledOffset!=mainItemDisplayer.mInitialScroll) {
                //if scroll position changed
                boolean scrollUp = (scrolledOffset - mainItemDisplayer.mInitialScroll) < 0;
                mainItemDisplayer.mInitialScroll = scrolledOffset;

               if (scrollUp){
                   Log.d("Scrolling", "UP");

               } else {
                   //mainItemDisplayer.setEnabled(false);
                   //Scrolling down
                   Log.d("Scrolling", "DOWN");
                   FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mainItemDisplayer.getLayoutParams();
                   //layoutParams.setMargins(0, mainItemDisplayer.mInitialScroll, 0, 0);

                   layoutParams.height += scrolledOffset;
                   mainItemDisplayer.setLayoutParams(layoutParams);
                   //((FrameLayout.LayoutParams) mainItemDisplayer.getLayoutParams()).setMarginEnd(mainItemDisplayer.mInitialScroll);
                   //mainItemDisplayer.setLayoutParams(layoutParams);
                   return;
               }
            }
            //mainItemDisplayer.setEnabled(true);
        }

I'm not sure I understand what you want to achieve, but it sounds like what you need are only two xml attributes for your listview : 我不确定我是否理解要实现的目标,但是听起来您所需要的只是listview的两个xml属性:

paddingTop="<yourmargin>dp"

and (the trick!) 和(把戏!)

clipToPadding="false"

.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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