所以,我有一个活动,比方说,它PetDetailActivity显示一个带有一些位图的轮播(我用来com.synnapps:carouselview:0.1.5处理我的轮播)。问题是 PetDetailActivity 加载了 0 大小的轮播,这可能图像仍在由线程处理。如何等待Picasso处理完URL,然后将其显示在新的Activity中?这是 PetDetailActivity 的代码:import ...public class PetDetailActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pet_detail); Intent i = getIntent(); Pet targetPet = (Pet)i.getSerializableExtra("PetObject"); ActionBar actionBar = getSupportActionBar(); if(actionBar!=null) actionBar.setDisplayHomeAsUpEnabled(true); //Creating a BitmapHandler object to download image from URL to Bitmap object using picasso. BitmapHandler bitmapHandler = new BitmapHandler(targetPet.getCarouselImageUrl()); final ArrayList<Bitmap> petCarouselBitmaps = bitmapHandler.getProcessedBitmap(); //The bitmap is being downloaded in other thread, so the activity is up and //CarouselView is still empty (petCarouselBitmaps.size() == 0) //So how to wait the bitmaps is processed, like show a loading screen on the UI? CarouselView petCarousel = findViewById(R.id.petCarousel); petCarousel.setPageCount(petCarouselBitmaps.size()); petCarousel.setImageListener(new ImageListener() { @Override public void setImageForPosition(int position, ImageView imageView) { imageView.setImageBitmap(petCarouselBitmaps.get(position)); } }); }...}
2 回答
小唯快跑啊
TA贡献1863条经验 获得超2个赞
问题: 。如何等待 Picasso 完成 URL 处理
解决方案:
我认为你可以使用 Target 回调:
private Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
}
@Override
public void onBitmapFailed() {
}
}
在加载图像时,您需要编写:
Picasso.with(this).load(myURL).into(target);
仅供参考:
onBitmapLoaded()
主要用于在实际加载到视图之前执行图像操作。Picasso.LoadedFrom
描述图像从何处加载,无论是内存、磁盘还是网络。
添加回答
举报
0/150
提交
取消