2014-10-08 155 views
0

我需要在滾動時向下滑動佈局,並在滾動停止時向上滑動。我試着用下面的代碼去做 ,但是面臨一些問題。問題是,當我第一次滾動,它完美的作品。如何在Scroll上從屏幕底部滑動/滑動佈局?

但是,當我嘗試再次滾動,動畫做的工作,它有點閃爍。 附上下面的代碼。

請讓我知道我要去哪裏錯了。

scrollviewDetails =(ScrollView)fragmentView.findViewById(R.id.sv_details); scrollviewDetails .setOnTouchListener(新View.OnTouchListener(){

 @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      switch (event.getAction()) { 
       case MotionEvent.ACTION_SCROLL: 
       case MotionEvent.ACTION_MOVE: 
        Log.e("SCROLL", "ACTION_SCROLL slidingDown==" +slidingDown); 
        if(!slidingDown){ 
         flActionNow.clearAnimation(); 
         slidingDown = true; 
         slidingUp = false; 
         flActionNow.setAnimation(slideDown); 
        } 
        break; 
       case MotionEvent.ACTION_DOWN: 
        Log.e("SCROLL", "ACTION_DOWN"); 
        break; 
       case MotionEvent.ACTION_CANCEL: 
       case MotionEvent.ACTION_UP: 
        Log.e("SCROLL", "SCROLL_STOP slidingUp==" +slidingUp); 
        if(!slidingUp){ 
         flActionNow.clearAnimation(); 
         slidingUp = true; 
         slidingDown = false; 
         flActionNow.setAnimation(slideUp); 
        } 
        break; 
      } 
      return false; 
     } 
    }); 

滑下ANIM:

<set xmlns:android="http://schemas.android.com/apk/res/android" > 
    <translate 
     android:duration="1000" 
     android:fillAfter="true" 
     android:fromYDelta="0%p" 
     android:toYDelta="100%p" /> 
</set> 

向上滑動ANIM:

<set xmlns:android="http://schemas.android.com/apk/res/android" > 
    <translate 
     android:duration="1000" 
     android:fillAfter="true" 
     android:fillBefore="true" 
     android:fromYDelta="75%p" 
     android:toYDelta="0%p" /> 
</set> 

謝謝, 斯納

回答

0

甲愚蠢的錯誤我做了!使用startAnimation而不是se動畫工作! :)