Android 小部件图像切换器?
如何在小部件中使用图像切换器?
我的代码编译正常,但是当我尝试创建小部件时,出现错误:
膨胀 AppWidget AppWidgetProviderInfo(provider=ComponentInfo{test.basic/test.basic.HelloWorldWidget}): android.view.InflateException: Binary XML 时出错文件第 5 行:错误 膨胀类 android.widget.ImageSwitcher
我的图像切换器的 xml 代码是:
<ImageSwitcher android:id="@+id/image_switcher"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
和我创建视图工厂的代码是:
@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;
}
});
}
任何帮助将不胜感激。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为不可能在 AppWidget 中使用 ImageSwitcher。 AppWidget 文档 (http://developer.android.com/guide/topics/appwidgets/index.html) 列出了构建 AppWidget 时可能使用的七种小部件类型。而 ImageSwicher 并不在列表中。
最好的选择可能是使用 FrameLayout 或relativelayout,其中多个 ImageView 彼此堆叠,然后一一设置它们的可见性,直到只有当前所需的图像可见。
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.