所以,我有一個活動,比方說,它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
提交
取消