将View holder添加到StaggeredGridView

时间:2014-01-29 12:10:56

标签: android

我正在尝试将Viewholder添加到StaggeredGridView。我的StaggeredGridView目前的问题是滚动速度非常慢。

我可以将Viewholder添加到普通列表或GridViews,但是使用StaggeredGridView 让我感到困惑,因为我有多种布局。

这是我的StaggeredGridView适配器:

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        final LayoutParams lp;
        final View v;
        switch (position)
        {

            case 0:
            v = mInflater.inflate(R.layout.layout_big, parent, false);
            ImageView ImageView0 = (ImageView) v.findViewById(R.id.imageView1);
            imageLoader.DisplayImage(image_url[position]), ImageView0);
            ImageView0.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    //Do something
                }
            });
            lp = new LayoutParams(v.getLayoutParams());
            lp.span = 3;

            break;
            case 1:
                v = mInflater.inflate(R.layout.layout_normal, parent, false);
                ImageView ImageView1 = (ImageView) v.findViewById(R.id.imageView1);
                imageLoader.DisplayImage(image_url[position]), ImageView1);
                ImageView1.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View arg0) {
                //Do something
                    }
                });
                lp = new LayoutParams(v.getLayoutParams());
                lp.span = 2;
                break;
            case 2:
                v = mInflater.inflate(R.layout.layout_small, parent, false); 
                ImageView ImageView2 = (ImageView) v.findViewById(R.id.imageView1);
                imageLoader.DisplayImage(image_url[position]), ImageView2);
                ImageView2.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View arg0) {
                //Do something
                    }
                });
                lp = new LayoutParams(v.getLayoutParams());
                lp.span = 1;
                break;
            default:
                   v = mInflater.inflate(R.layout.layout_all_other_item, parent, false);
        lp = new LayoutParams(v.getLayoutParams());
                lp.span = 1;
                break;
        }
        v.setLayoutParams(lp);
        return v;
    }
}

在上面的代码中,项目布局会根据项目的位置进行更改。 我应该为每个案例创建多个ViewHolder吗?对于上述案例,我们就像三个观众一样。

0 个答案:

没有答案