3D相册 效果图如下 .

 

首先在sdcard上放几张jpg格式的图片(美女图片)。。。不然效果出不来的 , 注意必须要美女的相片。如果你是女的 ,必须放csdn男会员的相片,不然效果也出不来

  1. public class Main Activity   extends Activity {  
  2.     GestureDetector gesture;  
  3.     private static final String TAG = "B";  
  4. //  private List<Bitmap> bitmaps = new ArrayList<Bitmap>();;   
  5.     private List<String> filepathName = new ArrayList<String>();  
  6. //  private Bitmap bm;   
  7. //  private Matrix matrix;   
  8.     private Handler handler;  
  9.     private Runnable runnable;  
  10.     private static final String URL = "/sdcard";  
  11.     private static final String tempFile = "/sdcard/temp.txt";  
  12.     int mCenterX = 160;  
  13.     int mCenterY = 0;  
  14.     int i = 0;  
  15.       
  16.     ImageView mImageView1;  
  17.     ImageView mImageView2;  
  18.     /** Called when the activity is first created. */  
  19.     @Override  
  20.     public void onCreate(Bundle savedInstanceState) {  
  21.         super.onCreate(savedInstanceState);  
  22.       
  23.         File file = new File(tempFile);  
  24.         if(!file.exists()){  
  25.             getFiles(URL);  
  26.             writeFile(tempFile,filepathName);  
  27.         }  
  28.         filepathName = readFile(tempFile);  
  29.         setContentView(R.layout.main);    
  30.   
  31.   
  32.         FlingGuest sg = new FlingGuest(this);  
  33.         gesture = new GestureDetector(sg);  
  34.   
  35.         mImageView1 = (ImageView) findViewById(R.id.image1);  
  36.         mImageView2 = (ImageView) findViewById(R.id.image2);  
  37.           
  38.         mImageView1.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));  
  39.     }  
  40.     public void delFile(File file){  
  41.         if(file.exists()){  
  42.             file.delete();  
  43.         }  
  44.     }  
  45.     public void getFiles(String path){  
  46.         System.out.println(path);  
  47.         String filePath;  
  48.         String fileName;  
  49.         String extName;  
  50.         File file = new File(path);  
  51.         if(file.isDirectory()){  
  52.             File[] files = file.listFiles();  
  53.             for(File f:files){  
  54.                 getFiles(f.getAbsolutePath());  
  55.             }  
  56.         }else{  
  57.                 filePath = file.getAbsolutePath();  
  58.                 fileName = file.getName();  
  59.                 extName = fileName.substring(fileName.indexOf(".")+1);  
  60.                 if(extName.equals("jpg")||extName.equals("bmp")||extName.equals("gif")||extName.equals("png")){  
  61.                       
  62.                     filepathName.add(filePath);  
  63.                   
  64.             }  
  65.               
  66.         }  
  67.     }  
  68.       
  69.     public void leftMoveHandle() {  
  70.         Rotate3d leftAnimation = new Rotate3d(0, -9000, mCenterX, mCenterY);  
  71.         Rotate3d rightAnimation = new Rotate3d(9000.0f, 0.0f, mCenterX,mCenterY);  
  72.   
  73.         leftAnimation.setFillAfter(true);  
  74.         leftAnimation.setDuration(1000);  
  75.         rightAnimation.setFillAfter(true);  
  76.         rightAnimation.setDuration(1000);  
  77.           
  78.         mImageView1.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));  
  79.         if(i==filepathName.size()-1){  
  80.             i = -1;  
  81.         }  
  82.         i++;  
  83.         mImageView2.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));  
  84.         mImageView1.startAnimation(leftAnimation);  
  85.         mImageView2.startAnimation(rightAnimation);  
  86.           
  87.     }  
  88.   
  89.     public void rightMoveHandle() {  
  90.         Rotate3d leftAnimation = new Rotate3d(09000, mCenterX, mCenterY);  
  91.         Rotate3d rightAnimation = new Rotate3d(-9000.0f, 0.0f, mCenterX,mCenterY);  
  92.   
  93.         leftAnimation.setFillAfter(true);  
  94.         leftAnimation.setDuration(1000);  
  95.         rightAnimation.setFillAfter(true);  
  96.         rightAnimation.setDuration(1000);  
  97.           
  98.         mImageView1.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));  
  99.         if(i==0){  
  100.             i = filepathName.size();  
  101.         }  
  102.         i--;  
  103.         mImageView2.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));  
  104.         mImageView1.startAnimation(leftAnimation);  
  105.         mImageView2.startAnimation(rightAnimation);  
  106.     }  
  107.   
  108.     // called automatically, any screen action will Triggered it   
  109.     public boolean onTouchEvent(MotionEvent me) {  
  110.         return gesture.onTouchEvent(me);  
  111.     }  
  112.   
  113.     @Override  
  114.     protected void onDestroy() {  
  115.         filepathName.clear();  
  116.         super.onDestroy();  
  117.     }  
  118.     public void writeFile(String file,List<String> list){  
  119.         try {  
  120.             FileWriter fw = new FileWriter(new File(file));  
  121.             for(String s :list){  
  122.                 fw.write(s, 0, s.length());  
  123.                 fw.write("=");  
  124.             }  
  125.             fw.flush();  
  126.             fw.close();  
  127.         } catch (IOException e) {  
  128.             e.printStackTrace();  
  129.         }  
  130.     }  
  131.     public List<String> readFile(String filepath){  
  132.         List<String> list = new ArrayList<String>();  
  133.         StringBuffer sb = new StringBuffer();  
  134.         String[] s ;  
  135.         try {  
  136.             FileReader fr = new FileReader(new File(filepath));  
  137.             int length = 0;  
  138.             while((length=fr.read())!=-1){  
  139.                 sb.append((char)length);  
  140.             }  
  141.             s = sb.toString().split("=");  
  142.               
  143.             for(int i=0;i<s.length;i++){  
  144.                 list.add(s[i]);  
  145.             }  
  146.         } catch (FileNotFoundException e) {  
  147.             e.printStackTrace();  
  148.         } catch (IOException e) {  
  149.             e.printStackTrace();  
  150.         }  
  151.         return list;  
  152.     }  
  153.       
  154.       
  155. }  
         
                要demo的http://download.csdn.net/source/3453268

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值