Android: Imageswitcher
I have a ImageSwitcher and 2 buttons...'Next' and 'Previous' to slide images...But its animate my sliding only in one side from left to the right...How to fix that ? thanks... Inte
Solution 1:
change the in/out animation in the onClickListeners. try this: (not checked for syntax etc...)
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageSwitcher.setImageResource(imageIDs[0]);
nextButton = (Button) findViewById(R.id.next);
nextButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Animation out= AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
Animation in= AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
imageSwitcher = (ImageSwitcher) findViewById(R.id.switcher1);
imageSwitcher.setFactory(this);
imageSwitcher.setInAnimation(in);
imageSwitcher.setOutAnimation(out);
imageSwitcher.setImageResource(imageIDs[1]);
}
});
previousButton = (Button) findViewById(R.id.previous); previousButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Animation out= AnimationUtils.loadAnimation(this, android.R.anim.slide_out_left);
Animation in= AnimationUtils.loadAnimation(this, android.R.anim.slide_in_right);
imageSwitcher.setFactory(this);
imageSwitcher.setInAnimation(in);
imageSwitcher.setOutAnimation(out);
imageSwitcher.setImageResource(imageIDs[0]);
}
});
}
public View makeView() {
ImageView imageView = new ImageView(this);
imageView.setBackgroundColor(0xFF000000);
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setLayoutParams(new ImageSwitcher.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
return imageView; }
Post a Comment for "Android: Imageswitcher"