[英]how to load images in array to faster display android
您好,我在一個線程內運行一個onuithread,它有一個時間,每次變慢都會隨機變化,直到從列表中選擇2個項目為止。 我的問題是該物品帶有圖片,我的想法是每次更改名稱時圖片都應該更改,但是在添加圖片時它將顯示如下內容:跳過66幀! 該應用程序可能在其主線程上做太多工作。
有沒有一種方法可以將圖像加載到數組中,然后在runuithread中僅顯示它們而無需再次加載它們? 在我的runuithread中:
while (i < 400) {
try {
Thread.sleep(i);
// here you check the value of getActivity() and break up if needed
if (getActivity() == null) {
return;
}
getActivity().runOnUiThread(new Runnable() // start actions in UI thread
{
@Override
public void run() {
start_btn.setEnabled(false);
Collections.shuffle(numbers);
Collections.shuffle(players_list);
player1_tv.setText(players[players_list.get(0)]);
player2_tv.setText(players[players_list.get(1)]);
group1_tv.setText(all_teams.get(numbers.get(0)));
player1_iv.setImageResource(getResources().getIdentifier(pictures.get(numbers.get(0)),"drawable",con.getPackageName()));
group2_tv.setText(group.get(numbers.get(1)));
i += 30;
if (i > 420) {
start_btn.setEnabled(true);
}
}
});
} catch (InterruptedException e) {
// ooops
}
圖像可以作為Bitmap對象加載和存儲。 您可以從如下資源加載位圖:
Bitmap bm = BitmapFactory.decodeResource(getResources(), {resourceId});
然后可以設置圖像:
player1_iv.setImageBitmap(bm);
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.