Hi, Romain Guy. Thank you for replying. I added ret.setStartTime( AnimationUtils.currentAnimationTimeMillis() ); to buildTranslateAnimation in sample code, but the animation behavior seems to not change.
On 6月15日, 午後4:57, Romain Guy <[email protected]> wrote: > When you set the animation on your View, set the start time of the > Animation to AnimationUtils.currentAnimationTimeMillis(). Otherwise, > the start time will be the first time your View is drawn, which is the > first time your View appears on screen. > > On Thu, Jun 10, 2010 at 6:55 AM, funnything > > > > <[email protected]> wrote: > > Hi. > > When I apply some animation to the view, which is out of window, the > > animation not start immediately. > > And then, I scroll the screen to show the animation target view, the > > animation will start. > > I hope to the animation will start immediately when it apply. Any > > ideas? > > Bellow is sample code. Thank you. > > > public class AnimationValidationActivity extends Activity { > > private ViewSwitcher _viewSwitcher; > > private Button _button; > > > /** > > * utility method for animation > > */ > > private Animation buildTranslateAnimation( float fromXDelta , > > float toXDelta , float fromYDelta , float toYDelta ) { > > Animation ret = new TranslateAnimation( fromXDelta , > > toXDelta , fromYDelta , toYDelta ); > > ret.setDuration( 1000 ); > > > return ret; > > } > > > /** > > * build view in place of layout.xml > > */ > > private View buildView() { > > ScrollView ret = new ScrollView( this ); > > ret.setLayoutParams( new > > LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT , > > LinearLayout.LayoutParams.WRAP_CONTENT ) ); > > > LinearLayout parent = new LinearLayout( this ); > > parent.setLayoutParams( new > > LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT , > > LinearLayout.LayoutParams.WRAP_CONTENT ) ); > > parent.setOrientation( LinearLayout.VERTICAL ); > > ret.addView( parent ); > > > _viewSwitcher = new ViewSwitcher( this ); > > _viewSwitcher.setLayoutParams( new > > LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT , > > 100 ) ); > > parent.addView( _viewSwitcher ); > > > View spacer = new View( this ); > > spacer.setLayoutParams( new > > LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT , > > getWindow() > > .getWindowManager().getDefaultDisplay().getHeight() ) ); > > parent.addView( spacer ); > > > _button = new Button( this ); > > _button.setText( "button" ); > > parent.addView( _button ); > > > return ret; > > } > > > �...@override > > public void onCreate( Bundle savedInstanceState ) { > > super.onCreate( savedInstanceState ); > > setContentView( buildView() ); > > > _viewSwitcher.setFactory( new ViewSwitcher.ViewFactory() { > > �...@override > > public View makeView() { > > TextView view = new > > TextView( AnimationValidationActivity.this ); > > view.setLayoutParams( new > > ViewSwitcher.LayoutParams( ViewSwitcher.LayoutParams.FILL_PARENT , > > ViewSwitcher.LayoutParams.FILL_PARENT ) ); > > view.setBackgroundColor( 0xffffffff ); > > > view.setText( "foobar" ); > > > return view; > > } > > } ); > > > _button.setOnClickListener( new View.OnClickListener() { > > �...@override > > public void onClick( View v ) { > > > _viewSwitcher.setInAnimation( buildTranslateAnimation( > > _viewSwitcher.getWidth() , > > 0 , 0 , 0 ) ); > > > _viewSwitcher.setOutAnimation( buildTranslateAnimation( 0 , - > > _viewSwitcher.getWidth() , 0 , 0 ) ); > > > int color = new Random().nextInt(); > > > _viewSwitcher.getNextView().setBackgroundColor( 0xff000000 | color & > > 0xffffff ); > > _viewSwitcher.showNext(); > > } > > } ); > > } > > } > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Developers" group. > > To post to this group, send email to [email protected] > > To unsubscribe from this group, send email to > > [email protected] > > For more options, visit this group at > >http://groups.google.com/group/android-developers?hl=en > > -- > Romain Guy > Android framework engineer > [email protected] > > Note: please don't send private questions to me, as I don't have time > to provide private support. All such questions should be posted on > public forums, where I and others can see and answer them -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

