How to use ImageSwitcher without a gallery

When looking at the ApiDemos example in the Android SDK (1.5), there is a great example of using ImageSwitcher with a Gallery object to provide โ€œchange imageโ€ actions.

In the application that I am looking for for writing, starting with the development of Android, there are three images that I want to possess / scroll, so ImageSwitcher looks like a great solution. However, I [not necessarily] want to have thumbnails in the gallery. I want either a swipe action and / or a button to cause scrolling to the previous / next image in the set.

The ImageSwitcher example in ApiDemos uses the Gallery and does nothing without this gallery.

If anyone has a suggestion to bind some kind of button controller or a U / I swipe object, I would appreciate a pointer.

Sorry to ask such a question at the novice level.

Thanks.

+4
source share
1 answer

You can use it as follows:

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 a Drawable

+1
source

Source: https://habr.com/ru/post/1300698/


All Articles