【发布时间】:2014-06-12 17:37:32
【问题描述】:
我想在我的图像切换器中有效地加载大型位图,为此我一直在使用毕加索,但现在我被困在这一点上。如果没有 Picasso 很多 OOMs 和其他讨厌的异常,请告诉我是否也可以将这个库与 Image Switcher 一起使用。
如果是,请提供示例代码。
谢谢!
imswitch.setFactory(new ViewFactory() {
@Override
public View makeView() {
ImageView imageView = new ImageView(getApplicationContext());
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
return imageView;
}
} );
和点击:
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
currentIndex++;
// If index reaches maximum reset it
if(currentIndex==messageCount)
currentIndex=0;
ImageView imageView = (ImageView)findViewById(R.id.imswitch);
Picasso.with(getApplicationContext()).load(imageIds[currentIndex]).into(imageView);
Toast.makeText(getApplicationContext(), "Pressed "+currentIndex,Toast.LENGTH_LONG).show();
}
【问题讨论】:
-
你有什么问题?
-
我有一堆大的位图,我想在图像切换器上显示它们,想知道毕加索在这里是否有帮助。
-
您的图片是否来自互联网?如果是真的,那么你可以使用 picasso 来获取这些图像,
-
不,我已将图像存储在可绘制目录中,我想在图像切换器中显示它们。我知道如何使用 Picasso 在 ImageView 上设置图像,但我不知道对 Image Switcher 做同样的事情
标签: android picasso imageswitcher