2012-03-13 74 views
2

這是我的第一個應用程序,所以我不使用java上的代碼。Android - gridview滾動問題(非常慢的滾動)

我有一個從SD卡的顯示縮略圖的gridview,但我不能有一個光滑的滾動。

如果我把/ *治療部分* /如果滾動是像我想要的,但他們是重複的內容和一部分圖片不顯示。

這裏是我的代碼:

-activity:

 GridView gridview = (GridView) findViewById(R.id.gridview1); 
    String[] projection = {MediaStore.Images.Media._ID}; 
    String path ="/mnt/sdcard/Pictures"; 
    // Create the cursor pointing to the SDCard 
    cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
      projection, 
      //MediaStore.Images.Media.DATA + " like ? ", 
      //new String[] {"%Pictures%Sopi%"}, 
      "_data LIKE '%" + path + "/%'",     
      null, 
      MediaStore.Images.Media._ID); 

    // Get the column index of the Media Image ID 
    columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID); 

    gridview.setAdapter(new ImageAdapterTest(RoomRawActivity.this)); 

-imageAdapater(獲得視圖):

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

    Log.v("adapter - getView","getView start!!"); 
    //Toast.makeText(mContext, "getView start!!"+position, 0).show(); 

    //Move cursor to current position 
    RoomRawActivity.cursor.moveToPosition(position); 

    ImageView picturesView; 

    if (convertView == null) { 

     picturesView = new ImageView(mContext); 

      /* treatment */ 

// Get the current value for the requested column 
int imageID = RoomRawActivity.cursor.getInt(RoomRawActivity.columnIndex); 
// obtain the image URI 
Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID)); 
String url = uri.toString(); 

//Set the content of the image based on the image URI 
int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length())); 
Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(mContext.getContentResolver(), 
     originalImageId, 
     MediaStore.Images.Thumbnails.MINI_KIND, 
     null); 
     picturesView.setPadding(5, 5, 5, 5); 
     picturesView.setBackgroundResource(R.drawable.border_grid_pics); 

     picturesView.setImageBitmap(b); 

     picturesView.setScaleType(ImageView.ScaleType.FIT_XY); 
      /* END treatment */ 
     } 
    }else{ 
     picturesView = (ImageView) convertView; 
    } 



    return picturesView; 
} 

非常感謝! David。

+0

如果我改變由MICRO_KIND MINI_KIND滾動順暢,但所有的圖像具有相同的尺寸(我想肖像和風景大拇指)。 – 2012-03-13 15:31:28

回答