我需要在滚动时向下滑动布局,并在滚动停止时向上滑动。我试过这样做 使用以下代码,但面临一些问题。问题是,当我第一次滚动时,它完美地工作。
但是当我再次尝试滚动时,动画效果很好,它有点闪烁。 附上以下代码。
让我知道我哪里出错了。
scrollviewDetails =(ScrollView)fragmentView.findViewById(R.id.sv_details); scrollviewDetails .setOnTouchListener(new 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;
}
} );
SLIDE DOWN 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>
滑行动画:
<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 :(得分:0)
我犯了一个愚蠢的错误!使用startAnimation而不是setAnimation工作! :)