第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在Android中等待Picasso完成加載圖像?

如何在Android中等待Picasso完成加載圖像?

守著一只汪 2023-06-28 15:52:40
所以,我有一個(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ò)。


查看完整回答
反對(duì) 回復(fù) 2023-06-28
?
鳳凰求蠱

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊

我認(rèn)為您可以使用占位符,然后加載圖像,它將顯示在圖像視圖中。而如果你想延遲使用可以使用Thread.sleep(5000).



查看完整回答
反對(duì) 回復(fù) 2023-06-28
  • 2 回答
  • 0 關(guān)注
  • 176 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)