Android中的网格视图图像的阶 [英] Order of images in Grid View in Android

查看:328
本文介绍了Android中的网格视图图像的阶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有中有一个网格视图图库Android应用程序。在这个网格视图我展示的图像在全屏,当用户点击一个图像。它的工作原理相当不错。但问题是,网格视图正确显示图像时出现在第一时间在屏幕上,但顺序随机变化,当用户滚动下来看到更多的图像。这里是我的code以下的适配器,您可以看看的图片。

I have an android application which has a grid view gallery in it. On this grid view I'm showing images in full screen when the user clicks on an image. It works quite well. But the problem is grid view shows the images correctly when they appear on the screen in the first time, but the order is changing randomly when user scrolls it down to see more images. Here is my code below for adapters and you can take a look to the pictures.

    public class GridGallery extends BaseAdapter {

    Context context;

    public GridGallery(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return urlList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

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

        System.gc();

        ImageView view;

        if(convertView == null) {

            view = new ImageView(context);

            view.setScaleType(ImageView.ScaleType.FIT_CENTER);
            view.setLayoutParams(new GridView.LayoutParams(screenWidth/4, screenHeight/4));
            view.setAdjustViewBounds(false);
            view.setPadding(2, 2, 2, 2);

            imageLoader.DisplayImage(urlList.get(position), view);

            System.gc();

        }else {
            view = (ImageView) convertView;
        }

        System.gc();

        return view;
    }

}

在这里,我怎么设置下面的适配器,

And here how I set the adapter below,

GridView g = (GridView) findViewById(R.id.myGrid);
        g.setAdapter(new GridGallery(context));

        isGalleryVisible = false;

        g.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

                myPagerAdapter = new MyPagerAdapter(context);
                pager = (ViewPager) findViewById(R.id.gallery_view);
                pager.setAdapter(myPagerAdapter);
                pager.setCurrentItem(position);

                isGalleryVisible = true;

            }
        });

下面是我的屏幕截图,它重演,当我把它的滚动。我每次向下滚动,时间回到顶部自己的位置是随机变化的。

Here are my screen shots, It repeats itself when I scroll it. And every time I scroll down and go back to top their places are changing randomly.

任何帮助将AP preciated。先谢谢了。

Any help will appreciated. Thanks in advance.

推荐答案

啊,我只是遇到了同样的问题现在。我还使用费多尔的延迟加载concept.I我不知道多远,这将是有益的,这是否是正确的做法。但它毕竟解决了这个问题对我来说。

Yeah, I just faced the same problem right now. I am also using Fedor's lazy loading concept.I am not sure how far this will be helpful and whether this is the right approach. But still it solved the problem for me.

我不得不做在一个小的修改在 getView()

I had to do a little modification in the getView(),

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

        System.gc();

        ImageView view;

        if(convertView == null) {

            view = new ImageView(context);

            view.setScaleType(ImageView.ScaleType.FIT_CENTER);
            view.setLayoutParams(new GridView.LayoutParams(screenWidth/4, screenHeight/4));
            view.setAdjustViewBounds(false);
            view.setPadding(2, 2, 2, 2);



            System.gc();

        }else {
            view = (ImageView) convertView;
        }
          if(view!=null)
            {
                   imageLoader.DisplayImage(urlList.get(position), view);
                   notifyDataSetChanged();  //Calling this helped to solve the problem. 
            }

        System.gc();

        return view;
    }

这篇关于Android中的网格视图图像的阶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆