GridView没有顺利滚动

时间:2013-12-13 05:45:25

标签: android gridview android-custom-view

我在可绘制文件夹中有100多个图像我在GridView中创建图库,但面临滚动问题。尽管我使用了ViewHolder ...

,但gridView的滚动并不顺畅

这是我的代码......

public class MainActivity extends Activity {
int[100] Names_images =    {R.drawable.img1,R.drawable.img3,R.drawable.img4,R.drawable.img5,R.drawable.img6,...};//100 images

  String[100] names = {"name1","name2","name3","name4","name5","name6",...};// 100 names    
GridView gridview; 
CustomizedGridAdapter1 adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

gridview = (GridView) findViewById(R.id.gridView);

adapter = new CustomizedGridAdapter1();
gridview.setAdapter(adapter);

}


 static class viewHolderClass{
     TextView Name;
     ImageView name_img;
     TextView Number;
    }
         public class CustomizedGridAdapter1 extends BaseAdapter {

    LayoutInflater inflater=null; 
    @Override
    public int getCount() {
        return names.length;
    }

    @Override
    public Object getItem(int position) {

        return position;
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

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

        viewHolderClass viewHolder=null;


        if(v == null){
        inflater = (LayoutInflater)          (MainActivity.this).getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
         v = inflater.inflate(R.layout.gridblock,parent, false);

         viewHolder = new viewHolderClass();

         viewHolder.Name = (TextView)v.findViewById(R.id.name);
         viewHolder.name_img = (ImageView)v.findViewById(R.id.name_image);
         viewHolder.Number = (TextView)v.findViewById(R.id.number);

         v.setTag(viewHolder);
         }else{
             viewHolder = (viewHolderClass)v.getTag();
         }

    viewHolder.Name.setText(names[position]);
    viewHolder.name_img.setImageResource(Names_images[position]);
    viewHolder.Number.setText(String.valueOf(position+1));  


        return v;
    }
  }//end of outer Class

2 个答案:

答案 0 :(得分:1)

更改您的getItem,如下所示:

@Override
public Object getItem(int position) {

    return names[position];
}

答案 1 :(得分:1)

尝试使用图像模糊加载程序,如:

https://github.com/nostra13/Android-Universal-Image-Loader