WEB开发网
开发学院手机开发Android 开发 Android 使用Gallery实现图片“多级联动” 阅读

Android 使用Gallery实现图片“多级联动”

 2010-08-11 10:47:00 来源:WEB开发网   
核心提示:11:12: private Bitmap[] bitmaps;13:14: public AlbumAdapter(Context context) {15: this.context = context;16: this.cursor = context.getContentResolver().query(17:

11:

12: private Bitmap[] bitmaps;

13:

14: public AlbumAdapter(Context context) {

15: this.context = context;

16: this.cursor = context.getContentResolver().query(

17: MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null, null, null,

18: MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);

19: bitmaps = new Bitmap[cursor.getCount()];

20: initBitmaps();

21: }

22:

23: /**

24: * 初始化专辑封面图片

25: */

26: private void initBitmaps() {

27: if (cursor.moveToFirst()) {

28: do {

29: bitmaps[cursor.getPosition()] = MusicUtils.getArtwork(context, -1, cursor

30: .getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID)));

31: } while (cursor.moveToNext());

32: }

33: }

34:

35: public int getCount() {

36: if (cursor != null) {

37: return cursor.getCount();

38: }

39: return 0;

40: }

41:

42: public Object getItem(int position) {

43: return position;

44: }

45:

46: public long getItemId(int position) {

47: if (cursor != null) {

48: cursor.moveToPosition(position);

49: return cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID));

50: }

51: return 0;

52: }

53:

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

55: ImageView iv = new ImageView(context);

56: iv.setLayoutParams(new Gallery.LayoutParams(100, 100));

57: iv.setAdjustViewBounds(true);

58: iv.setImageBitmap(bitmaps[position]);

59: return iv;

60: }

61:

62: }

三、Activity

Tags:Android 使用 Gallery

编辑录入:coldstar [复制链接] [打 印]
赞助商链接