97干视频,99国产精品懂色,亚洲精品99久久久久中文字幕,伊人五月丁香综合AⅤ,国产精品成人免费999

  您的位置:華清遠(yuǎn)見教育科技集團(tuán) >> 新聞動(dòng)態(tài) >> Android資料 >> Android中如何實(shí)現(xiàn)圖像瀏覽  
 
Android中如何實(shí)現(xiàn)圖像瀏覽
分享到:

在Android中,對(duì)于多媒體文件,系統(tǒng)提供了媒體掃描(MediaScanner)服務(wù),在掃描到相應(yīng)的文件后,該文件的信息會(huì)被存到特定的數(shù)據(jù)庫(kù)中。對(duì)于圖像文件,也是如此。對(duì)于SD卡,其URI地址為android. provider.MediaStore.Images. Media. EXTERNAL_CONTENT_URI,對(duì)于終端空間,其URI地址為android. provider.MediaStore.Images. Media. INTERNAL_CONTENT_URI。數(shù)據(jù)庫(kù)包含的字段包括:DATA、SIZE、DISPLAY_NAME、TITLE、DATE_ADDED、DATE_MODIFIED、MIME_TYPE等。

package com.miaozl.test;

在UI層面,多個(gè)圖像的瀏覽通常是通過(guò)Gallery來(lái)實(shí)現(xiàn)的,下面是利用Gallery進(jìn)行圖像瀏覽的一個(gè)實(shí)例:

import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.Gallery;
    import android.widget.ImageView;
    public class GalleryActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Gallery g = (Gallery) findViewById(R.id.gallery);
            g.setAdapter(new GalleryAdapter(this));
        }
        private class GalleryAdapter extends BaseAdapter {
            private Context mContext;
            private Integer[] mImageIds = {
                R.drawable.photo1,
                R.drawable.photo2,
                R.drawable.photo3,
                R.drawable.photo4,
                R.drawable.photo5,
                R.drawable.photo6,
            };
        public GalleryAdapter(Context c) {
                mContext = c;
            }
        public int getCount() {
            return mImageIds.length;
        }
        public Object getItem(int position) {
            return position;
        }
        public long getItemId(int position) {
            return position;
        }
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView i = new ImageView(mContext);
            i.setImageResource(mImageIds[position]);
            return i;
            }
        }
    }

下圖是圖像瀏覽的效果圖。

如果加載的是數(shù)據(jù)庫(kù)中的圖片,基于的適配器的基類為CursorAdapter。

 更多相關(guān)文章

·Android圖像旋轉(zhuǎn)源碼分享
·Android中多媒體縮略圖的生成
·Android 圖像縮放之bitmap類
·Android 2D圖像處理基本接口
·Android HTML5視頻播放
·Android基于MediaPlayer的視頻播放