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

时间:2015-03-23 22:43:29

标签: android listview

是否可以阻止ListView滚动?我目前有一个ListView,上面有一个边距,可以显示一个位于后面的图像视图。我的目标是覆盖人​​员向上滚动时位于ImageView后面的ListView,因为ListView向上滚动它也会关闭它最终隐藏ImageView的边距{1}}位于它后面。我目前正在做这件事,但我想弄清楚如何停止ListView上的滚动动画,直到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);
        }

1 个答案:

答案 0 :(得分:0)

我不确定我理解你想要达到的目标,但听起来你需要的只是列表视图的两个xml属性:

paddingTop="<yourmargin>dp"

和(诀窍!)

clipToPadding="false"