In looking at the ApiDemos example in the Android (1.5) SDK, there is a fine example of using an ImageSwitcher, with a Gallery object to provide the "change image" actions.
The application I'm looking to write, starting into Android development, has three images that I want to be able to pane/scroll through, so ImageSwitcher looks like a fine solution. However, I don't [necesarily] want to have thumbnails in a gallery. I want either a swipe action, and/or a button, to cause a scroll to the previous/next image in the set.
The example ImageSwitcher in ApiDemos uses a Gallery, and without that Gallery, doesn't do anything.
If someone has a suggestion of a way to bind some sort of button controller, or a U/I swipe object, I would appreciate the pointer.
Sorry to ask such a newbie level question.
Thanks.
You can use it like this:
public class GalleryActivity extends Activity implements ViewFactory{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
iSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher1);
iSwitcher.setFactory(this);
iSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
iSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
iSwitcher.setImageDrawable(fetchImage(mImageURLS[0]));
iSwitcher.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// CLICK HANDLER
// Change image like:
// iSwitcher.setImageDrawable(fetchImage(mImageURLS[1]));
}
});
}
@Override
public View makeView() {
ImageView iView = new ImageView(this);
iView.setScaleType(ImageView.ScaleType.FIT_CENTER);
iView.setLayoutParams(new
ImageSwitcher.LayoutParams(
LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
iView.setBackgroundColor(0xFF000000);
return iView;
}
}
fetchImage(mImageURLS[0])
returns Drawable object
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With