隨筆 - 0, 文章 - 264, 評論 - 170, 引用 - 0
          數據加載中……

          android中展示圖片

           1    1public class Images extends Activity  
           2    2. {  
           3    3.     private Uri[] mUrls;  
           4    4.     String[] mFiles=null;  
           5    5.   
           6    6.     public void onCreate(Bundle icicle)  
           7    7.     {  
           8    8.   
           9    9.         super.onCreate(icicle);  
          10   10.         setContentView(R.layout.images);  
          11   11.   
          12   12.         File images = Environment.getDataDirectory();  
          13   13.         File[] imagelist = images.listFiles(new FilenameFilter(){  
          14   14.         @override  
          15   15.         public boolean accept(File dir, String name)  
          16   16.         {  
          17   17.             return ((name.endsWith(".jpg"))||(name.endsWith(".png"))  
          18   18.         }  
          19   19.     });  
          20   20.         mFiles = new String[imagelist.length];  
          21   21.   
          22   22.         for(int i= 0 ; i< imagelist.length; i++)  
          23   23.         {  
          24   24.             mFiles[i] = imagelist[i].getAbsolutePath();  
          25   25.         }  
          26   26.         mUrls = new Uri[mFiles.length];  
          27   27.   
          28   28.         for(int i=0; i < mFiles.length; i++)  
          29   29.         {  
          30   30.             mUrls[i] = Uri.parse(mFiles[i]);     
          31   31.         }     
          32   32.   
          33   33.         Gallery g = (Gallery) findViewById(R.id.gallery);  
          34   34.         g.setAdapter(new ImageAdapter(this));  
          35   35.         g.setFadingEdgeLength(40);  
          36   36.     }  
          37   37.     public class ImageAdapter extends BaseAdapter{  
          38   38.           
          39   39.         int mGalleryItemBackground;  
          40   40.         public ImageAdapter(Context c)  {     
          41   41.             mContext = c;     
          42   42.         }  
          43   43.         public int getCount(){  
          44   44.             return mUrls.length;  
          45   45.         }  
          46   46.         public Object getItem(int position){  
          47   47.             return position;  
          48   48.         }  
          49   49.         public long getItemId(int position) {  
          50   50.             return position;  
          51   51.         }  
          52   52.         public View getView(int position, View convertView, ViewGroup parent){  
          53   53.             ImageView i = new ImageView(mContext);  
          54   54.   
          55   55.             i.setImageURI(mUrls[position]);  
          56   56.             i.setScaleType(ImageView.ScaleType.FIT_XY);  
          57   57.             i.setLayoutParams(new Gallery.LayoutParams(260210));  
          58   58.             return i;  
          59   59.         }     
          60   60.         private Context mContext;  
          61   61.         }     
          62   62.     } 

          posted on 2010-10-26 09:34 小一敗涂地 閱讀(1988) 評論(0)  編輯  收藏 所屬分類: android+移動開發

          主站蜘蛛池模板: 尉犁县| 巩留县| 闻喜县| 鄂托克前旗| 兴城市| 津市市| 龙江县| 岑溪市| 祁东县| 申扎县| 平邑县| 阳东县| 内丘县| 汤阴县| 马龙县| 乡宁县| 平泉县| 如东县| 崇义县| 隆子县| 宜州市| 建阳市| 金乡县| 安吉县| 陈巴尔虎旗| 准格尔旗| 新昌县| 运城市| 唐河县| 镇赉县| 中超| 湖州市| 凯里市| 张家界市| 长海县| 陆河县| 格尔木市| 赣州市| 苍溪县| 温州市| 平舆县|