2014-07-07 64 views
0

我做了一个平滑的滚动到定义的位置。如何知道滚动动画何时结束?

smoothScrollTo(0, 1000); 

此方法执行后 - 我做了几个操作。但我想做他们 - 滚动动画结束后。

我想检测滚动动画何时完成。我该怎么做?

+0

不知道,但你可以用'onScrollChanged'? [参考](http://stackoverflow.com/a/1800267/1777090) –

+0

@PurpleDroid yeap,我可以。但也许存在更简单的方法? :) –

+0

确定:)不知道它然后:) –

回答

2

我必须做这样的,

final ScrollView mScrollView = (ScrollView) findViewById(R.id.scrollview); 
    layoutSponsorBax.setVisibility(View.VISIBLE); 

    Timer timer = new Timer(); 

    TimerTask task = new TimerTask() { 
     @Override 
     public void run() { 
      runOnUiThread(new Runnable() { 
       @Override 
       public void run() { 
        ViewGroup relativeL = (ViewGroup) mScrollView 
          .getChildAt(mScrollView.getChildCount() - 1); 
        final int sVH = mScrollView.getBottom() 
          - mScrollView.getTop(); 

        View notePad = relativeL.getChildAt(2); 
        final int svHeight = 800; 
        Log.i("svHeight", "svHeight : " + svHeight); 
        final float duration = 2000; 
        ctt = new CountDownTimer((int) duration, 1) { 
         int temp = 0; 


         public void onTick(long millisUntilFinished) { 
          try { 
           Log.i("millisUntilFinished", 
             "millisUntilFinished : " 
               + millisUntilFinished); 
           Log.i("Height- Temp", "Temp : " + temp); 
           mScrollView.scrollTo(0, temp); 
           temp = (int) (((svHeight) - (millisUntilFinished/duration) 
             * (svHeight))); 
          } catch (ArithmeticException e) { 
           e.printStackTrace(); 
          } catch (Exception e) { 
           e.printStackTrace(); 
          } 
         } 

         public void onFinish() { 
         } 
        }.start(); 
       } 
      }); 
     } 
    }; 
    int duration = 1400; 
    timer.schedule(task, duration); 

请这可能是帮助你

+0

其实我创建的解决方案。默认动画时间为250毫秒。 –

+0

但你的答案其实是对的。我可以使用Timer任务来处理动画,所以加上一个。 –