亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

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

守著一只汪 2023-06-28 15:52:40
所以,我有一個活動,比方說,它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描述圖像從何處加載,無論是內存、磁盤還是網絡。


查看完整回答
反對 回復 2023-06-28
?
鳳凰求蠱

TA貢獻1825條經驗 獲得超4個贊

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



查看完整回答
反對 回復 2023-06-28
  • 2 回答
  • 0 關注
  • 177 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號