所以,我有一個(gè)活動(dòng),比方說,它PetDetailActivity顯示一個(gè)帶有一些位圖的輪播(我用來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貢獻(xiàn)1863條經(jīng)驗(yàn) 獲得超2個(gè)贊
問題: 。如何等待 Picasso 完成 URL 處理
解決方案:
我認(rèn)為你可以使用 Target 回調(diào):
private Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
}
@Override
public void onBitmapFailed() {
}
}
在加載圖像時(shí),您需要編寫:
Picasso.with(this).load(myURL).into(target);
僅供參考:
onBitmapLoaded()
主要用于在實(shí)際加載到視圖之前執(zhí)行圖像操作。Picasso.LoadedFrom
描述圖像從何處加載,無論是內(nèi)存、磁盤還是網(wǎng)絡(luò)。

鳳凰求蠱
TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊
我認(rèn)為您可以使用占位符,然后加載圖像,它將顯示在圖像視圖中。而如果你想延遲使用可以使用Thread.sleep(5000)
.
添加回答
舉報(bào)
0/150
提交
取消