2012-03-13 11 views
2

これは私の最初のアプリですので、私はJavaのコードには使用しません。Android - gridviewスクロールの問題(非常に遅いスクロール)

私はsdcardからサムネイルを表示するグリッドビューを持っていますが、滑らかなスクロールはできません。

スクロールのようなものが/ *処置部分* /を入れた場合、それらは重複した内容であり、写真の一部は表示されません。

- 活性:

 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; 
} 

多くのおかげ

は、ここに私のコードです!デビッド。 。

+0

私はMICRO_KINDでMINI_KINDを変更した場合、スクロールは滑らかであるが、すべての画像は、(私は親指を肖像画や風景たい)と同じサイズを有しています。 –

答えて

5

GetViewメソッドを整理する必要があります。

  • あなたは
  • がパフォーマンス

役に立つかもしれない、このリンクを探してimageViews上のSET SCALEを使用しないようにしよう AsyncTaskを使用し、getViewメソッドであなたの画像リソースを設定すべきではありません。

Use AsyncTask to Load Bitmap Images

http://developer.android.com/training/improving-layouts/smooth-scrolling.html http://www.programmingmobile.com/2012/03/buttery-smooth-list-scrolling-in.html