Question

I'm creating a simple homescreen widget that displays a simple slide show of images. For switching between images, I'm using an AdapterViewFlipper that simply displays the next image every 1.5 seconds. This works fine but during the transition from one image to the next, it seems to fade-out and fade-in (almost like a transition animation), and I would like to disable it. How can I do so? I've disabled the animation in the layout XML but it doesn't help. I'm bewildered.

Here's my layout containing the flipper:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/widget_frame"
    android:orientation="vertical"
    android:textAlignment="gravity" >

    <AdapterViewFlipper
        android:id="@+id/image_flipper"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/widget_icon"
        android:animateLayoutChanges="false"
        android:autoStart="true"
        android:flipInterval="1500" >

    </AdapterViewFlipper>

</LinearLayout>

When the appwidget, loads, I bind the flipper to it's adapter:

Intent ittSlides = new Intent(ctxContext, SlideService.class);
ittSlides.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, intInstance);
ittSlides.setData(Uri.fromParts("content", String.valueOf(new Random().nextInt()), null));
ittSlides.putExtra("data", strContent);

RemoteViews remView = new RemoteViews(ctxContext.getPackageName(), R.layout.widget);
remView.setRemoteAdapter(R.id.image_flipper, ittSlides);

AppWidgetManager.getInstance(ctxContext).updateAppWidget(intInstance, remView);

..and here's my actual adapter that powers this.

public class SlideFactory implements RemoteViewsFactory {
    private JSONArray jsoImages;
    private final Context ctxContext;
    private RemoteViews remView;

    public SlideFactory(Context ctxContext, Intent ittIntent) {

        remView = new RemoteViews(ctxContext.getPackageName(), R.layout.image);
        this.ctxContext = ctxContext;
        try {
            jsoImages = new JSONArray(ittIntent.getStringExtra("data"));
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }

    }

    @Override
    public RemoteViews getViewAt(int intPosition) {
        try {
            remView.setImageViewUri(R.id.dopper_image, Uri.parse(jsoImages.getString(intPosition)));
        } catch (final JSONException e) {
            Log.e("SlideFactory", "Unknown error encountered", e);
            BugSenseHandler.sendException(e);
        } catch (final Exception e) {
            Log.e("SlideFactory", "Unknown error encountered", e);
            BugSenseHandler.sendException(e);
        }
        return remView;
    }

    ...
    ...
    ...
}

As you can see, there's nothing special in the adapter. I'm simply reading the image from the disk and setting it to a layout that that has an ImageView which i then give to the AdapterViewFlipper

Was it helpful?

Solution

I was also having the same issue and found the solution by chance. This is more like tricky solution. This is actually disabling animation effect by adding an animation with no animation setting.

1.Add two XMLs under anim folder. I would say in.xml and out.xml but you could use any or use one XML for both.

2.Add a blank objectAnimator element in the XMLs

<?xml version="1.0" encoding="UTF-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"/>
  1. Add android:inAnimation="@anim/in" and android:outAnimation="@anim/out" in the AdapterViewFlipper

  2. Build you application and magically, the animation will be disabled!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top