简体   繁体   English

如何加载数组中的图像以更快地显示android

[英]how to load images in array to faster display android

Hello i am running a onuithread inside a thread and it has a times and it will be changing randomly each time slower until it select 2 items from the list. 您好,我在一个线程内运行一个onuithread,它有一个时间,每次变慢都会随机变化,直到从列表中选择2个项目为止。 my problem is that this items has pictures and my idea is to everytime the name change the picture should change but when adding the pictures it will display something like this: Skipped 66 frames! 我的问题是该物品带有图片,我的想法是每次更改名称时图片都应该更改,但是在添加图片时它将显示如下内容:跳过66帧! The application may be doing too much work on its main thread. 该应用程序可能在其主线程上做太多工作。

is there a way to load the images in the array and then in the runuithread only display them without loading them again? 有没有一种方法可以将图像加载到数组中,然后在runuithread中仅显示它们而无需再次加载它们? here in my 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
                }

The image can be loaded and stored as a Bitmap object. 图像可以作为Bitmap对象加载和存储。 You can load Bitmap from a resource like this: 您可以从如下资源加载位图:

Bitmap bm = BitmapFactory.decodeResource(getResources(), {resourceId});

Then you can set the image: 然后可以设置图像:

player1_iv.setImageBitmap(bm);

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM