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();
}
} );
}
}