我在我的應用程序中使用Gridview顯示SD卡上的文件夾中的圖像... 我的問題是GridView中的滾動,它不像Gallery應用程序那樣流暢。 這裏的適配器代碼 -GridView滾動不光滑
public class GridViewAdapter extends BaseAdapter {
// Declare variables
private Activity activity;
private String[] filepath;
private String[] filename;
private static LayoutInflater inflater = null;
public GridViewAdapter(Activity a, String[] fpath, String[] fname) {
activity = a;
filepath = fpath;
filename = fname;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return filepath.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.gridview_item, null);
// Locate the ImageView in gridview_item.xml
ImageView img = (ImageView) vi.findViewById(R.id.image);
// Set file name to the TextView followed by the position
TextView txt = (TextView) vi.findViewById(R.id.name);
// Decode the filepath with BitmapFactory followed by the position
Bitmap bmp = BitmapFactory.decodeFile(filepath[position]);
// Set the decoded bitmap into ImageView
img.setImageBitmap(bmp);
txt.setText(filename[position]);
return vi;
}
}
如何來解決這個問題,使滾動順暢?
您應該使用ViewHolder – Rachit