-1

我想在运行时创建 600 个图像视图并在运行时将其添加到线性布局。这会导致我的用户界面阻塞。当所有图像视图创建并添加到线性布局时,我的活动就会出现。如何解决这个问题。

请为此提供帮助。

       for(int index = 0; index < ProductItemArray.Image_URL.length; index++)
        {
            ImageView bottomImageView = new ImageView(context);
            bottomImageView.setTag(index);

            if(Helper.isTablet(context))
                bottomImageView.setLayoutParams(new Gallery.LayoutParams(VirtualMirrorActivity.convertDpToPixel(100, context), VirtualMirrorActivity.convertDpToPixel(100, context)));
            else
                bottomImageView.setLayoutParams(new Gallery.LayoutParams(VirtualMirrorActivity.convertDpToPixel(80, context), VirtualMirrorActivity.convertDpToPixel(80, context)));

            UrlImageViewHelper.setUrlDrawable(bottomImageView, ProductItemArray.Image_URL[index]);
            bottomImageView.setBackgroundResource(R.layout.border);
            linearLayout3.addView(bottomImageView);
            bottomImageView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    final int position = (Integer) v.getTag();
                    linearLayout.removeAllViews();
                    Thread newThread = new Thread(new Runnable() {
                        public void run() {
                            isAlreadyExistInWishlist = true;
                            URL url_1 = null;
                            try {
                                VMProductListPaging.productUrl = ProductItemArray.Image_small_URL[position];
                                VMProductListPaging.productId = ProductItemArray.productId[position];
                                VMProductListPaging.productName = ProductItemArray.product_Name[position];

                                url_1 = new URL(ProductItemArray.Image_small_URL[position]);
                                bmp = BitmapFactory.decodeStream(url_1.openConnection().getInputStream());
                                isExecuted = true;
                                bitmapModelsHandler.sendMessage(bitmapModelsHandler.obtainMessage());
                            }
                            catch (Exception e) {
                                //Toast.makeText(context,"Sorry!! This link appears to be broken",Toast.LENGTH_LONG).show();
                            }
                        }
                    });
                    newThread.start();
                }
            });
        }
4

1 回答 1

4

同时在内存中存储 600 张图像可能不是一个好主意。

您应该考虑通过适配器(使用 ListView、Gallery、GridView、Spinner 等)使用一些延迟加载,该适配器将管理视图的回收/释放。

于 2012-11-20T08:18:53.470 回答