用图像平滑滚动gridview

时间:2013-10-30 19:13:52

标签: android gridview scroll smooth

我一直在为社区建立一个应用程序,我是其中的朋友, 我使用gridview来显示图像,并且对于每个图像,我将进行布局,当用户按下图像时,它将开始相关活动。 但是我遇到滚动问题,它不顺畅。

这是适配器代码;

class MyAdapter extends BaseAdapter {
private List<Item> items = new ArrayList<Item>();
private LayoutInflater inflater;

public MyAdapter(Context context) {
    inflater = LayoutInflater.from(context);
    items.add(new Item("White",R.drawable.austra,1));
    items.add(new Item("p",R.drawable.aus,2));
    items.add(new Item("BBR",R.drawable.black,3));
    items.add(new Item("Black",R.drawable.black_s,4));
    items.add(new Item("Black",R.drawable.black_stan,5));
    items.add(new Item("Black",R.drawable.black_sum,6));
    items.add(new Item("Blue ",R.drawable.blue_s,7));
    items.add(new Item("Brown ",R.drawable.brown_br,8));
    items.add(new Item("Brown ",R.drawable.br,9));
    items.add(new Item("Buff ",R.drawable.bu10));
    items.add(new Item("Buff ",R.drawable.buf,11));
    items.add(new Item("Columb",R.drawable.colum,12));
    items.add(new Item("Corn",R.drawable.corni,13));
    items.add(new Item("Cuck",R.drawable.cuck,14));
    items.add(new Item("Dar",R.drawable.dar,15));
    items.add(new Item("Del",R.drawable.del,16));
    items.add(new Item("Dom",R.drawable.dom17));
    items.add(new Item("East",R.drawable.east,18));
    items.add(new Item("Ger",R.drawable.ger,19));
    items.add(new Item("Gol",R.drawable.gol,20));
    items.add(new Item("Go",R.drawable.gol,21));
    items.add(new Item("Gol",R.drawable.gol,22));
    items.add(new Item("Gol",R.drawable.gol,23));
    items.add(new Item("Gold",R.drawable.gol,24));
    items.add(new Item("Hamps",R.drawable.ha25));
    items.add(new Item("Jers",R.drawable.jer,26));
    items.add(new Item("Jer",R.drawable.jerse,27));
    items.add(new Item("Li",R.drawable.ligh,28));
    items.add(new Item("Mottl",R.drawable.mot,29));
    items.add(new Item("Nak",R.drawable.nak,30));
    items.add(new Item("Orp",R.drawable.orp,31));
    items.add(new Item("Partri",R.drawable.part,32));
    items.add(new Item("Barre",R.drawable.ply,33));
    items.add(new Item("Rho",R.drawable.rho,34));
    items.add(new Item("Salmo",R.drawable.sal,35));
    items.add(new Item("Sicil",R.drawable.sicil,36));
    items.add(new Item("Silve",R.drawable.silver_d,37));
    items.add(new Item("Sil",R.drawable.silver_l,38));
    items.add(new Item("S.P Eg",R.drawable.silv,39));
    items.add(new Item("Sil",R.drawable.si,40));
    items.add(new Item("Speck",R.drawable.speck,41));
    items.add(new Item("W.C ",R.drawable.white_cr,42));
    items.add(new Item("W.C B",R.drawable.white_c,43));
    items.add(new Item("Whi",R.drawable.white_l,44));
    items.add(new Item("Whi",R.drawable.white_p,45));
    items.add(new Item("Whit",R.drawable.white,46));
    items.add(new Item("Whit",R.drawable.white_sultan,47));
    items.add(new Item("Wy",R.drawable.wyan,48));
}


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

@Override
public Object getItem(int i) {
    return items.get(i);
}

@Override
public long getItemId(int i) {
    return items.get(i).drawableId;
}

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

    if (convertView == null) { 
        convertView = inflater.inflate(R.layout.grid_item, parent, false);
        holder = new ViewHolderItem(); 
        holder.name = (TextView) convertView.findViewById(R.id.text); 
        holder.picture = (ImageView) convertView.findViewById(R.id.picture); 

       convertView.setTag(holder); 
   } else { 
       holder = (ViewHolderItem) convertView.getTag(); 
   } 
   Item item = (Item)getItem(position);
   holder.name.setText(item.name); 
   holder.picture.setImageResource(item.drawableId);

   return convertView; 
}

private class Item {
    int id;
    final String name;
    final int drawableId;

    Item(String name, int drawableId ,int id) {
        this.id = id;
        this.name = name;
        this.drawableId = drawableId;
    }
}

private class ViewHolderItem{
    ImageView picture;
    TextView name;
}


}

0 个答案:

没有答案