3D相册 效果图如下

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

public class Main Activity   extends Activity {
	GestureDetector gesture;
	private static final String TAG = "B";
//	private List<Bitmap> bitmaps = new ArrayList<Bitmap>();;
	private List<String> filepathName = new ArrayList<String>();
//	private Bitmap bm;
//	private Matrix matrix;
	private Handler handler;
	private Runnable runnable;
	private static final String URL = "/sdcard";
	private static final String tempFile = "/sdcard/temp.txt";
	int mCenterX = 160;
	int mCenterY = 0;
	int i = 0;
	
	ImageView mImageView1;
	ImageView mImageView2;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	
		File file = new File(tempFile);
		if(!file.exists()){
			getFiles(URL);
			writeFile(tempFile,filepathName);
		}
		filepathName = readFile(tempFile);
		setContentView(R.layout.main);	


		FlingGuest sg = new FlingGuest(this);
		gesture = new GestureDetector(sg);

		mImageView1 = (ImageView) findViewById(R.id.image1);
		mImageView2 = (ImageView) findViewById(R.id.image2);
		
		mImageView1.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));
	}
	public void delFile(File file){
		if(file.exists()){
			file.delete();
		}
	}
	public void getFiles(String path){
		System.out.println(path);
		String filePath;
		String fileName;
		String extName;
		File file = new File(path);
		if(file.isDirectory()){
			File[] files = file.listFiles();
			for(File f:files){
				getFiles(f.getAbsolutePath());
			}
		}else{
				filePath = file.getAbsolutePath();
				fileName = file.getName();
				extName = fileName.substring(fileName.indexOf(".")+1);
				if(extName.equals("jpg")||extName.equals("bmp")||extName.equals("gif")||extName.equals("png")){
					
					filepathName.add(filePath);
				
			}
			
		}
	}
	
	public void leftMoveHandle() {
		Rotate3d leftAnimation = new Rotate3d(0, -90, 0, 0, mCenterX, mCenterY);
		Rotate3d rightAnimation = new Rotate3d(90, 0, 0.0f, 0.0f, mCenterX,mCenterY);

		leftAnimation.setFillAfter(true);
		leftAnimation.setDuration(1000);
		rightAnimation.setFillAfter(true);
		rightAnimation.setDuration(1000);
		
		mImageView1.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));
		if(i==filepathName.size()-1){
			i = -1;
		}
		i++;
		mImageView2.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));
		mImageView1.startAnimation(leftAnimation);
		mImageView2.startAnimation(rightAnimation);
		
	}

	public void rightMoveHandle() {
		Rotate3d leftAnimation = new Rotate3d(0, 90, 0, 0, mCenterX, mCenterY);
		Rotate3d rightAnimation = new Rotate3d(-90, 0, 0.0f, 0.0f, mCenterX,mCenterY);

		leftAnimation.setFillAfter(true);
		leftAnimation.setDuration(1000);
		rightAnimation.setFillAfter(true);
		rightAnimation.setDuration(1000);
		
		mImageView1.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));
		if(i==0){
			i = filepathName.size();
		}
		i--;
		mImageView2.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));
		mImageView1.startAnimation(leftAnimation);
		mImageView2.startAnimation(rightAnimation);
	}

	// called automatically, any screen action will Triggered it
	public boolean onTouchEvent(MotionEvent me) {
		return gesture.onTouchEvent(me);
	}

	@Override
	protected void onDestroy() {
		filepathName.clear();
		super.onDestroy();
	}
	public void writeFile(String file,List<String> list){
		try {
			FileWriter fw = new FileWriter(new File(file));
			for(String s :list){
				fw.write(s, 0, s.length());
				fw.write("=");
			}
			fw.flush();
			fw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public List<String> readFile(String filepath){
		List<String> list = new ArrayList<String>();
		StringBuffer sb = new StringBuffer();
		String[] s ;
		try {
			FileReader fr = new FileReader(new File(filepath));
			int length = 0;
			while((length=fr.read())!=-1){
				sb.append((char)length);
			}
			s = sb.toString().split("=");
			
			for(int i=0;i<s.length;i++){
				list.add(s[i]);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return list;
	}
	
	
}
          
                要demo的留下邮箱        或者http://download.csdn.net/source/3453268

  

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值