【问题标题】:In gallery item click how can i display image view and grid view?在图库项目中单击我如何​​显示图像视图和网格视图?
【发布时间】:2012-07-23 21:14:59
【问题描述】:

当我单击要显示图像和网格视图的图库项目时,我的 android 应用程序中有一个图库。当我在图库中只有三张图像并单击它正确显示时,我完成了。但是现在我在画廊中有七张图片,每个画廊项目都有四张图片来显示画廊。在这个我只使用 drwawable 图像数组。这次我得到了一个例外,Java.lang.OutOfMemory
我使用下面的代码

   public ImageThemeAdapter(Context c, Integer[] mImageIds) {
     imagesId=mImageIds;
     bitmap=new Bitmap[imagesId.length];
     mContext = c;
     TypedArray ta=obtainStyledAttributes(R.styleable.Gallery1);
        imageBackground=ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
        ta.recycle();
        for (int i = 0; i <imagesId.length; i++) {
           bitmap[i]=BitmapFactory.decodeResource(mContext.getResources(),imagesId[i]);
        }
    }

    public int getCount() {
        return bitmap.length;
    }

    public Object getItem(int position) {
        return bitmap[position];  
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {   

        ImageView i = new ImageView(mContext);

        i.setImageBitmap(bitmap[position]);
        i.setScaleType(ImageView.ScaleType.FIT_XY);
        i.setLayoutParams(new Gallery.LayoutParams(130, 120));
       // i.setLayoutParams(new Gallery.LayoutParams((ScreenWidth*80)/100, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
        i.setBackgroundResource(imageBackground);
        return i;   
    }

请提供任何建议。提前致谢。 我有这样的要求

【问题讨论】:

标签: android image gridview gallery


【解决方案1】:

请使用 Allocation Tracker(Windows -> Shows View -> Other -> Android -> Allocation Tracker) 重复上述步骤,找出不同对象的内存分配情况。

主要原因可能是由于您在创建 GridView 时自定义视图的布局,并且在运行时您将创建图库图像的缩略图。我们可能必须创建一个网格视图,一次可用的图像数量最少。

【讨论】:

    猜你喜欢
    • 2019-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多