隨筆 - 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+移動開發

          主站蜘蛛池模板: 屏南县| 武威市| 樟树市| 响水县| 长汀县| 蛟河市| 额尔古纳市| 廉江市| 平谷区| 象州县| 渭源县| 灵石县| 德庆县| 彩票| 昆山市| 衡阳县| 乳源| 达日县| 息烽县| 昌宁县| 拜泉县| 大兴区| 奇台县| 二手房| 石景山区| 剑河县| 衡山县| 东城区| 汶川县| 茂名市| 太仆寺旗| 藁城市| 炎陵县| 嘉祥县| 南投县| 大庆市| 察雅县| 尚义县| 滨海县| 濮阳县| 广水市|