package com.gallery;
import android.content.Context;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Transformation;
import android.widget.Gallery;
import android.widget.ImageView;
public class GalleryFlow extends Gallery {
private Camera mCamera = new Camera();
private int mMaxRotationAngle = 60;
private int mMaxZoom = -120;
private int mCoveflowCenter;
public GalleryFlow(Context context) {
super(context);
this.setStaticTransformationsEnabled(true);
}
public GalleryFlow(Context context, AttributeSet attrs) {
super(context, attrs);
this.setStaticTransformationsEnabled(true);
}
public GalleryFlow(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.setStaticTransformationsEnabled(true);
}
public int getMaxRotationAngle() {
return mMaxRotationAngle;
}
public void setMaxRotationAngle(int maxRotationAngle) {
mMaxRotationAngle = maxRotationAngle;
}
public int getMaxZoom() {
return mMaxZoom;
}
public void setMaxZoom(int maxZoom) {
mMaxZoom = maxZoom;
}
private int getCenterOfCoverflow() {
return (getWidth() - getPaddingLeft() - getPaddingRight()) / 2
+ getPaddingLeft();
}
private static int getCenterOfView(View view) {
return view.getLeft() + view.getWidth() / 2;
}
protected boolean getChildStaticTransformation(View child, Transformation t) {
final int childCenter = getCenterOfView(child);
final int childWidth = child.getWidth();
int rotationAngle = 0;
t.clear();
t.setTransformationType(Transformation.TYPE_MATRIX);
if (childCenter == mCoveflowCenter) {
transformImageBitmap((ImageView) child, t, 0);
} else {
rotationAngle = (int) (((float) (mCoveflowCenter - childCenter) / childWidth) * mMaxRotationAngle);
if (Math.abs(rotationAngle) > mMaxRotationAngle) {
rotationAngle = (rotationAngle < 0) ? -mMaxRotationAngle
: mMaxRotationAngle;
}
transformImageBitmap((ImageView) child, t, rotationAngle);
}
return true;
}
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mCoveflowCenter = getCenterOfCoverflow();
super.onSizeChanged(w, h, oldw, oldh);
}
private void transformImageBitmap(ImageView child, Transformation t,
int rotationAngle) {
mCamera.save();
final Matrix imageMatrix = t.getMatrix();
final int imageHeight = child.getLayoutParams().height;
final int imageWidth = child.getLayoutParams().width;
final int rotation = Math.abs(rotationAngle);
// 在Z轴上正向移动camera的视角,实际效果为放大图片。
// 如果在Y轴上移动,则图片上下移动;X轴上对应图片左右移动。
mCamera.translate(0.0f, 0.0f, 100.0f);
// As the angle of the view gets less, zoom in
if (rotation < mMaxRotationAngle) {
float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
mCamera.translate(0.0f, 0.0f, zoomAmount);
}
// 在Y轴上旋转,对应图片竖向向里翻转。
// 如果在X轴上旋转,则对应图片横向向里翻转。
mCamera.rotateY(rotationAngle);
mCamera.getMatrix(imageMatrix);
imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
mCamera.restore();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
android Gallery倒影效果
共34个文件
jpg:9个
class:9个
java:4个
5星 · 超过95%的资源 需积分: 9 29 下载量 157 浏览量
2011-10-20
14:58:25
上传
评论
收藏 737KB RAR 举报
温馨提示
android Gallery倒影效果android Gallery倒影效果android Gallery倒影效果android Gallery倒影效果android Gallery倒影效果android Gallery倒影效果
资源推荐
资源详情
资源评论
收起资源包目录
Gallery.rar (34个子文件)
Gallery
.project 845B
src
com
gallery
ImageAdapter.java 3KB
ActivityMain.java 798B
GalleryFlow.java 4KB
AndroidManifest.xml 636B
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
drawable
img0130.jpg 33KB
img0330.jpg 41KB
img0354.jpg 24KB
img0030.jpg 47KB
img0001.jpg 16KB
img0230.jpg 29KB
img0200.jpg 38KB
img0300.jpg 12KB
img0100.jpg 25KB
drawable-mdpi
icon.png 3KB
layout
layout_gallery.xml 452B
values
strings.xml 170B
assets
gen
com
gallery
R.java 1KB
default.properties 364B
.classpath 280B
bin
resources.ap_ 278KB
com
gallery
R$layout.class 383B
R$drawable.class 658B
R$attr.class 319B
R$id.class 366B
R.class 482B
R$string.class 406B
ImageAdapter.class 4KB
GalleryFlow.class 4KB
ActivityMain.class 1KB
classes.dex 9KB
Gallery.apk 285KB
共 34 条
- 1
资源评论
- ywlm4232013-03-22效果很炫!
- soft_nzs2014-06-27很好的例子 感谢分享
- s4788536302014-03-02效果还不错
- feifei4030685092012-09-14正是我要的效果,非常好, 谢谢。
socket_cpp
- 粉丝: 2
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功