Question

how do I use an imageswitcher in a widget?

my code compiles fine, but when I try to create my widget it gives an error:

Error inflating AppWidget AppWidgetProviderInfo(provider=ComponentInfo{test.basic/test.basic.HelloWorldWidget}): android.view.InflateException: Binary XML file line #5: Error inflating class android.widget.ImageSwitcher

my xml code for my imageswitcher is:

<ImageSwitcher android:id="@+id/image_switcher"
    android:layout_width="fill_parent" android:layout_height="fill_parent" />

and my code for creating a viewfactory is:

    @Override
public void onEnabled(final Context context) {
    readImages(context);

    ImageSwitcher imageSwitcher = getImageSwitcher(context);
    imageSwitcher.setFactory(new ViewFactory() {

        public View makeView() {
            ImageView imageView = new ImageView(context);
            imageView.setBackgroundColor(0xFF000000);
            imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            imageView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
            return imageView;
        }
    });
}

any help would be strongly appreciated.

thank you

Was it helpful?

Solution

I don't think it's possible to use an ImageSwitcher in an AppWidget. The AppWidget documentation (http://developer.android.com/guide/topics/appwidgets/index.html) lists seven widget types that may be used when building an AppWidget. And ImageSwicher is not on the list.

Your best bet will probably be to use a FrameLayout or a RelativeLayout with multiple ImageView's stacked on top of each other, and then set their visibility one by one until only the currently desired image is visible.

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