问题描述
有什么可旋转木马动画图像,作为iPhone可用库http://cocoacontrols.com/platforms/ios/controls/icarousel
我已经使用Cover Flow功能,但它是不会放弃的效果就像iCarousel在iphone,所以如果一些其他技巧通过它我可以实现这个请给我谢谢
可使用此code您查找样子狂欢游行
主要的CoverFlow活动
包pl.polidea.coverflow;
进口的java.util.ArrayList;
进口android.app.Activity;
进口android.os.Bundle;
进口android.view.View;
进口android.view.ViewGroup.LayoutParams;
进口android.widget.AdapterView;
进口android.widget.AdapterView.OnItemClickListener;
进口android.widget.AdapterView.OnItemSelectedListener;
进口android.widget.BaseAdapter;
进口android.widget.TextView;
/ **
*本类CoverFlowTestingActivity。
* /
公共类CoverFlowActivity延伸活动{
私人的TextView TextView的;
BaseAdapter coverImageAdapter;
/ *
*(非Javadoc中)
*
* @see android.app.Activity#的onCreate(android.os.Bundle)
* /
私人INT [] DEFAULT_RESOURCE_LIST = {R.drawable.img1,R.drawable.img2,
R.drawable.img3,R.drawable.img4,R.drawable.img5,R.drawable.img6,
R.drawable.img7,R.drawable.img8};
私人INT [] DEFAULT_RESOURCE_LIST1 = {R.drawable.img1a,
R.drawable.img2a,R.drawable.img3a,R.drawable.img4a,
R.drawable.img5a,R.drawable.img6a,R.drawable.img7a,
R.drawable.img8a};
公共静态的ArrayList<为imageData> i11Set;
@覆盖
保护无效的onCreate(最终捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
TextView的=(的TextView)findViewById(this.getResources()。则getIdentifier(
状态文本,ID,pl.polidea.coverflow));
//注意下面的资源使用则getIdentifier允许进口采取
//这个库的库。
/ *
*最后的CoverFlow coverFlow1 =(的CoverFlow)
* findViewById(this.getResources()。则getIdentifier(的CoverFlow,身份证,
*pl.polidea.coverflow)); setupCoverFlow(coverFlow1,假);
* /
最后的CoverFlow reflectingCoverFlow =(的CoverFlow)findViewById(本
.getResources()。则getIdentifier(coverflowReflect,身份证,
pl.polidea.coverflow));
setupCoverFlow(reflectingCoverFlow,真正的);
}
/ **
*设置Cover Flow功能。
*
* @参数mCoverFlow
* m个的Cover Flow
* @参数反映
*的反映
* /
私人无效setupCoverFlow(最终的CoverFlow mCoverFlow,
最终布尔反映){
尝试
{
i11Set =新的ArrayList<为imageData>();
对于(INT RESOURCEID:DEFAULT_RESOURCE_LIST1){
i11Set.add(新的ImageData(RESOURCEID));
// Global.i11.add(新的ImageData(RESOURCEID));
}
如果(反映){
coverImageAdapter =新ReflectingImageAdapter(
新ResourceImageAdapter(此,i11Set),3);
} 其他 {
coverImageAdapter =新ResourceImageAdapter(这一点,i11Set);
}
mCoverFlow.setAdapter(coverImageAdapter,-1);
mCoverFlow.setSelection(3,真正的);
setupListeners(mCoverFlow);
}
赶上(例外五)
{
e.printStackTrace();
}
}
/ **
*设置监听器。
*
* @参数mCoverFlow
*新的监听器
* /
私人无效setupListeners(最终的CoverFlow mCoverFlow){
mCoverFlow.setOnItemClickListener(新OnItemClickListener(){
@覆盖
公共无效onItemClick(最终适配器视图<>父,
最终的视图中查看,INT位置,最终长ID){
尝试
{
i11Set =新的ArrayList<为imageData>();
对于(INT RESOURCEID = 0; RESOURCEID< DEFAULT_RESOURCE_LIST1.length; RESOURCEID ++){
{
如果(RESOURCEID ==位置){
i11Set.add(新的ImageData(
DEFAULT_RESOURCE_LIST [RESOURCEID]));
} 其他 {
i11Set.add(新的ImageData(
DEFAULT_RESOURCE_LIST1 [RESOURCEID]));
}
}
// Global.i11.add(新的ImageData(RESOURCEID));
}
/ *为(INT RESOURCEID:DEFAULT_RESOURCE_LIST){
i11Set.add(新的ImageData(RESOURCEID));
// Global.i11.add(新的ImageData(RESOURCEID));
} * /
coverImageAdapter =新ReflectingImageAdapter(
新ResourceImageAdapter(CoverFlowActivity.this,
i11Set),3);
mCoverFlow.setAdapter(coverImageAdapter,-1);
mCoverFlow.setSelection(位置,真正的);
//coverImageAdapter.notifyDataSetChanged();
// mCoverFlow.invalidate();
}
赶上(例外五)
{
e.printStackTrace();
}
}
});
mCoverFlow.setOnItemSelectedListener(新OnItemSelectedListener(){
@覆盖
公共无效onItemSelected(最终适配器视图<>父,
最终的视图中查看,最终诠释的位置,最终长的id){
textView.setText(项目中选择:+ ID);
/ *
* coverImageAdapter =新ReflectingImageAdapter(新
* ResourceImageAdapter(CoverFlowActivity.this),位置);
* coverImageAdapter.notifyDataSetChanged();
* mCoverFlow.setAdapter(coverImageAdapter,位置);
* mCoverFlow.setSelection(位置,真正的);
* mCoverFlow.invalidate();
* /
}
@覆盖
公共无效onNothingSelected(最终适配器视图<>母公司){
textView.setText(没什么点击!);
}
});
}
}
Coverflow.java
包pl.polidea.coverflow;
进口android.content.Context;
进口android.content.res.TypedArray;
进口android.graphics.Camera;
进口android.graphics.Matrix;
进口android.util.AttributeSet;
进口android.util.Log;
进口android.view.MotionEvent;
进口android.view.View;
进口android.view.animation.Transformation;
进口android.widget.Gallery;
进口android.widget.ImageView;
进口android.widget.SpinnerAdapter;
/ **
* Cover Flow功能的实现。
*
* /
公共类的CoverFlow扩展库{
/ **
*图形相机用于转化ImageViews的基质。
* /
私人最终相机mCamera =新相机();
/ **
*最大角度儿童ImageView的将由旋转。
* /
私人诠释mMaxRotationAngle = 60;
/ **
*中央孩子在最大变焦。
* /
私人诠释mMaxZoom = -220;
/ **
*该的CoverFlow的中心。
* /
私人诠释mCoveflowCenter;
/ **的图像高度。 * /
私人浮动imageHeight;
/ **的图像宽度。 * /
私人浮动ImageWidth等;
/ **反射的差距。 * /
私人浮动reflectionGap;
/ **的与反思。 * /
私人布尔withReflection;
/ **图像反射率。 * /
私人浮动imageReflectionRatio;
/ **
*获取图像高度。
*
返回:图像高度
* /
公众持股量getImageHeight(){
返回imageHeight;
}
/ **
*将图像高度。
*
* @参数imageHeight
*新的图像高度
* /
公共无效setImageHeight(最终浮动imageHeight){
this.imageHeight = imageHeight;
}
/ **
*获取图像的宽度。
*
返回:图像的宽度
* /
公众持股量getImageWidth(){
返回ImageWidth等;
}
/ **
*将图像的宽度。
*
* @参数ImageWidth等
*新的图像宽度
* /
公共无效setImageWidth(最终浮动ImageWidth等){
this.imageWidth = ImageWidth等;
}
/ **
*获取反射差距。
*
返回:反射差距
* /
公众持股量getReflectionGap(){
返回reflectionGap;
}
/ **
*设置反射差距。
*
* @参数reflectionGap
*新的反射差距
* /
公共无效setReflectionGap(最终浮动reflectionGap){
this.reflectionGap = reflectionGap;
}
/ **
*如果是与反思检查。
*
返回:真,如果是与反思
* /
公共布尔isWithReflection(){
返回withReflection;
}
/ **
*设置与反思。
*
* @参数withReflection
*新的与反思
* /
公共无效setWithReflection(最终布尔withReflection){
this.withReflection = withReflection;
}
/ **
*将图像反射率。
*
* @参数imageReflectionRatio
*新的图像反射率
* /
公共无效setImageReflectionRatio(最终浮动imageReflectionRatio){
this.imageReflectionRatio = imageReflectionRatio;
}
/ **
*获取图像的反射率。
*
返回:图像反射率
* /
公众持股量getImageReflectionRatio(){
返回imageReflectionRatio;
}
公众的CoverFlow(最终上下文的背景下){
超(上下文);
this.setStaticTransformationsEnabled(真正的);
}
公众的CoverFlow(最终上下文的背景下,最终的AttributeSet ATTRS){
这(背景下,ATTRS,android.R.attr.galleryStyle);
}
公众的CoverFlow(最终上下文的背景下,最终的AttributeSet ATTRS,最终诠释defStyle){
超(背景下,ATTRS,defStyle);
parseAttributes(背景下,ATTRS);
this.setStaticTransformationsEnabled(真正的);
}
/ **
*获取图像的最大旋转角度。
*
返回:该mMaxRotationAngle
* /
公众诠释getMaxRotationAngle(){
返回mMaxRotationAngle;
}
/ **
*设置。
*
* @参数适配器
*新的适配器
* /
公共无效setAdapter(最终SpinnerAdapter适配器,INT位置){
如果(!(适配器的instanceof AbstractCoverFlowImageAdapter)){
抛出新抛出:IllegalArgumentException(适配器应是来自
+ AbstractCoverFlowImageAdapter.class.getName());
}
最后AbstractCoverFlowImageAdapter coverAdapter =(AbstractCoverFlowImageAdapter)适配器;
coverAdapter.setWidth(ImageWidth等);
coverAdapter.setHeight(imageHeight);
如果(withReflection){
最后ReflectingImageAdapter reflectAdapter =新ReflectingImageAdapter(coverAdapter,位置);
reflectAdapter.setReflectionGap(reflectionGap);
reflectAdapter.setWidthRatio(imageReflectionRatio);
reflectAdapter.setWidth(ImageWidth等);
reflectAdapter.setHeight(imageHeight *(1 + imageReflectionRatio));
super.setAdapter(reflectAdapter);
} 其他 {
super.setAdapter(适配器);
}
}
/ **
*设置各图像的最大旋转角度。
*
* @参数maxRotationAngle
*在mMaxRotationAngle设置
* /
公共无效setMaxRotationAngle(最终诠释maxRotationAngle){
mMaxRotationAngle = maxRotationAngle;
}
/ **
*获取中间图像的最大变焦。
*
返回:该mMaxZoom
* /
公众诠释getMaxZoom(){
返回mMaxZoom;
}
/ **
*设置中心图像的最大缩放。
*
* @参数maxZoom
*在mMaxZoom设置
* /
公共无效setMaxZoom(最终诠释maxZoom){
mMaxZoom = maxZoom;
}
/ **
*获取的CoverFlow的中心。
*
返回:此的CoverFlow的中心。
* /
私人诠释getCenterOfCoverflow(){
返回(的getWidth() - getPaddingLeft() - getPaddingRight())/ 2 + getPaddingLeft();
}
/ **
*获取视图的中心。
*
返回:给定视图的中心。
* /
私有静态诠释getCenterOfView(最终查看视图){
返回view.getLeft()+ view.getWidth()/ 2;
}
/ **
* {@inheritDoc}
*
* @see #setStaticTransformationsEnabled(布尔)
* /
@覆盖
保护布尔getChildStaticTransformation(最后查看的孩子,最终变换T){
最终诠释childCenter = getCenterOfView(子);
最终诠释childWidth = child.getWidth();
INT rotationAngle = 0;
t.clear();
t.setTransformationType(Transformation.TYPE_MATRIX);
如果(childCenter == mCoveflowCenter){
transformImageBitmap((ImageView的)孩子,T,0);
} 其他 {
//child.setLayoutParams(new的LayoutParams(100,100));
rotationAngle =(INT)((浮动)(mCoveflowCenter - childCenter)/ childWidth * mMaxRotationAngle);
如果(Math.abs(rotationAngle)> mMaxRotationAngle){
rotationAngle = rotationAngle< 0? -mMaxRotationAngle:mMaxRotationAngle;
}
Log.d(转角,+ rotationAngle);
transformImageBitmap((ImageView的)孩子,T,rotationAngle);
}
返回true;
}
/ **
*这是布局过程调用时该视图的大小发生了变化。如果
*你刚才添加到视图层次,你所谓的老
* 0值。
*
* @参数W¯¯
*这种观点的电流宽度。
* @参数^ h
*这种观点的当前高度。
* @参数oldw
*这种观点的旧宽度。
* @参数oldh
*这种观点的旧高度。
* /
@覆盖
保护无效onSizeChanged(最终诠释W,最终诠释小时,最终诠释oldw,最终诠释oldh){
mCoveflowCenter = getCenterOfCoverflow();
super.onSizeChanged(W,H,oldw,oldh);
}
/ **
*经过的角度转换图像的位图。
*
* @参数的ImageView
* ImageView的,我们要旋转其位图的ImageView
* @参数吨
*转型
* @参数rotationAngle
*角度通过它旋转的位图
* /
私人无效transformImageBitmap(最终ImageView的孩子,最终变换T,最终诠释rotationAngle){
mCamera.save();
最终矩阵imageMatrix = t.getMatrix();
最终诠释身高= child.getLayoutParams()的高度。
。最终诠释宽度= child.getLayoutParams()宽度;
最终诠释旋转= Math.abs(rotationAngle);
mCamera.translate(0.0,0.0,100.0f);
//作为视图的角度变得更小,放大
如果(旋转< mMaxRotationAngle){
//child.setLayoutParams(new的LayoutParams(200200));
最终浮zoomAmount =(浮点)(mMaxZoom +旋转* 10.0);
mCamera.translate(0.0,0.0,zoomAmount);
}
mCamera.rotateY(rotationAngle);
mCamera.getMatrix(imageMatrix);
。imageMatrix preTranslate( - (宽度/ 2.0f), - (高度/ 2.0f));
imageMatrix.postTranslate((宽度/ 2.0f),(高度/ 2.0f));
mCamera.restore();
}
/ **
*解析的属性。
*
* @参数方面
*上下文
* @参数ATTRS
*在ATTRS
* /
私人无效parseAttributes(最终上下文的背景下,最终的AttributeSet ATTRS){
最后TypedArray A = context.obtainStyledAttributes(ATTRS,R.styleable.CoverFlow);
尝试 {
ImageWidth等= a.getDimension(R.styleable.CoverFlow_imageWidth,480);
imageHeight = a.getDimension(R.styleable.CoverFlow_imageHeight,320);
withReflection = a.getBoolean(R.styleable.CoverFlow_withReflection,假);
imageReflectionRatio = a.getFloat(R.styleable.CoverFlow_imageReflectionRatio,0.2F);
reflectionGap = a.getDimension(R.styleable.CoverFlow_reflectionGap,4);
setSpacing(-50);
} 最后 {
a.recycle();
}
}
/ * @覆盖
公共布尔onFling(MotionEvent E1,E2 MotionEvent,浮velocityX,
浮动velocityY){
// TODO自动生成方法存根
布尔leftScroll = isScrollingLeft(E1,E2);
浮动velX;
如果(leftScroll)
{
velX = 500;
}
其他
{
velX = -500;
}
返回super.onFling(E1,E2,velX,velocityY);
}
私人布尔isScrollingLeft(MotionEvent E1,E2 MotionEvent){
返回e2.getX()> e1.getX();
} * /
}
ResourceImageAdapter
包pl.polidea.coverflow;
进口java.lang.ref.WeakReference;
进口的java.util.ArrayList;
进口的java.util.HashMap;
进口的java.util.List;
进口的java.util.Map;
进口android.content.Context;
进口android.graphics.Bitmap;
进口android.graphics.drawable.BitmapDrawable;
进口android.util.Log;
/ **
*这个类是提供的图像从一组固定的资源适配器
* IDS。位图和ImageViews保持弱引用,以便他们可以
*垃圾收集清理时,没有必要。
*
* /
公共类ResourceImageAdapter扩展AbstractCoverFlowImageAdapter {
/ **不朽的标签。 * /
私有静态最后字符串标记= ResourceImageAdapter.class
.getSimpleName();
/ **不朽的DEFAULT_LIST_SIZE。 * /
私有静态最终诠释DEFAULT_LIST_SIZE = 20;
/ **不朽的IMAGE_RESOURCE_IDS。 * /
私有静态最后的名单,其中,整数GT; IMAGE_RESOURCE_IDS =新的ArrayList<整数GT;(
DEFAULT_LIST_SIZE);
/ **不朽的DEFAULT_RESOURCE_LIST。 * /
私有静态最终诠释[] DEFAULT_RESOURCE_LIST = {R.drawable.img1a,
R.drawable.img2a,R.drawable.img3a,R.drawable.img4a,
R.drawable.img5a,R.drawable.img6a,R.drawable.img7a,
R.drawable.img8a};
/ **位图的地图。 * /
私人最终地图<整型的WeakReference<位图>> bitmapMap =新的HashMap<整型的WeakReference<位图>>();
私人最终上下文的背景下;
私人的ImageData I1;
//私人的ArrayList<为imageData> I11 =新的ArrayList<为imageData>();
/ **
*创建与资源的图像组默认的适配器。
*
* @参数方面
*上下文
* /
公共ResourceImageAdapter(最终上下文的背景下,
ArrayList的<为imageData> i11get){
超();
this.context =背景;
setResources(i11get);
}
/ **
*替换与指定的资源。
*
* @参数resourceIds
*资源id的数组。
* /
公众最终同步无效setResources(ArrayList中<为imageData> resourceIds){
/ *
* IMAGE_RESOURCE_IDS.clear();
*
*为(最终诠释RESOURCEID:resourceIds){
* IMAGE_RESOURCE_IDS.add(RESOURCEID);
*
* Global.i11.add(新的ImageData(RESOURCEID)); }
* /
// Global.i11.clear();
尝试
{
Global.i11 =新的ArrayList<为imageData>();
Global.i11 = resourceIds;
Log.d(I11的大小,+ Global.i11.size());
notifyDataSetChanged();
}
赶上(例外五)
{
e.printStackTrace();
}
}
/ *
*(非Javadoc中)
*
* @see android.widget.Adapter#getCount将()
* /
@覆盖
公共同步INT getCount将(){
返回Global.i11.size();
}
/ *
*(非Javadoc中)
*
* @see pl.polidea.coverflow.AbstractCoverFlowImageAdapter#createBitmap(INT)
* /
@覆盖
受保护的位图createBitmap(最终诠释位置){
Log.v(TAG创建项目+位置);
最后的位图位=((BitmapDrawable)context.getResources()
.getDrawable(Global.i11.get(位置).getSetResourceId()))
.getBitmap();
bitmapMap.put(位置,新的WeakReference<位图>(位图));
返回的位图;
}
}
全局
包pl.polidea.coverflow;
进口的java.util.ArrayList;
公共类全局{
公共静态的ArrayList<为imageData> I11 =新的ArrayList<为imageData>();
}
的ImageData P>
包pl.polidea.coverflow;
公共类的ImageData {
私人诠释setResourceId;
公众的ImageData()
{}
公众的ImageData(INT RID){
超();
this.setResourceId =去掉;
}
公众诠释getSetResourceId(){
返回setResourceId;
}
公共无效setSetResourceId(INT setResourceId){
this.setResourceId = setResourceId;
}
}
ReflectingImageAdapter
包pl.polidea.coverflow;
进口android.R.color;
进口android.graphics.Bitmap;
进口android.graphics.Bitmap.Config;
进口android.graphics.Canvas;
进口android.graphics.Color;
进口android.graphics.ColorMatrix;
进口android.graphics.ColorMatrixColorFilter;
进口android.graphics.LinearGradient;
进口android.graphics.Matrix;
进口android.graphics.Paint;
进口android.graphics.PorterDuff.Mode;
进口android.graphics.PorterDuffXfermode;
进口android.graphics.Shader.TileMode;
进口android.util.Log;
/ **
*此适配器提供反射链接适配器图像。
*
* @author potiuk
*
* /
公共类ReflectingImageAdapter扩展AbstractCoverFlowImageAdapter {
/ **的连接适配器。 * /
私人最终AbstractCoverFlowImageAdapter linkedAdapter;
/ **
*图像和其反射差距。
* /
私人浮动reflectionGap;
/ **图像反射率。 * /
私人浮动imageReflectionRatio;
公众诠释ID;
私人INT位置= -1;
/ **
*设置宽比。
*
* @参数imageReflectionRatio
*新的宽度比
* /
公共无效setWidthRatio(最终浮动imageReflectionRatio){
this.imageReflectionRatio = imageReflectionRatio;
}
/ **
*创建反映适配器。
*
* @参数linkedAdapter
*适配器,它提供的图像获得的反射
* /
公共ReflectingImageAdapter(
最后AbstractCoverFlowImageAdapter linkedAdapter,INT ID){
超();
this.id = ID;
this.linkedAdapter = linkedAdapter;
}
/ **
*设置反射差距。
*
* @参数reflectionGap
*新的反射差距
* /
公共无效setReflectionGap(最终浮动reflectionGap){
this.reflectionGap = reflectionGap;
}
/ **
*获取反射差距。
*
返回:反射差距
* /
公众持股量getReflectionGap(){
返回reflectionGap;
}
/ *
*(非Javadoc中)
*
* @see pl.polidea.coverflow.AbstractCoverFlowImageAdapter#createBitmap(INT)
* /
@覆盖
受保护的位图createBitmap(INT位置){
// this.position =位置;
返回createReflectedImages(linkedAdapter.getItem(位置),位置);
}
/ **
*创建反射的图像。
*
* @参数originalImage
*原始图像
返回:真实的,如果成功
* /
公共位图createReflectedImages(位图originalImage,INT位置){
位图怀旧= NULL;
// Log.d(Id为,+ ID);
// Log.d(位置,位置+位置);
/ *如果(ID ==位置)
{* /
怀旧= originalImage;
/ *}
其他
{
怀旧= ConvertToBlackAndWhite(originalImage);
} * /
最终诠释宽度= sepia.getWidth();
最终诠释身高= sepia.getHeight();
最终矩阵的矩阵=新的Matrix();
矩阵preSCALE(1,-1)。
最后的位图reflectionImage = Bitmap.createBitmap(深褐色,0,
(INT)(高* imageReflectionRatio),宽度,
(INT)(高 - 高* imageReflectionRatio),矩阵,假);
最后的位图bitmapWithReflection = Bitmap.createBitmap(宽度,
(INT)(高+高* imageReflectionRatio)
Config.ARGB_8888);
最后的画布油画=新的Canvas(bitmapWithReflection);
canvas.drawBitmap(深褐色,0,0,NULL);
最后的油漆deafaultPaint =新的油漆();
deafaultPaint.setColor(color.transparent);
canvas.drawBitmap(reflectionImage,0,身高+ reflectionGap,NULL);
最终的涂料粉刷=新的油漆();
最后的LinearGradient着色器=新的LinearGradient(0,sepia.getHeight()
0,bitmapWithReflection.getHeight()+ reflectionGap,
0x70ffffff,至0x00FFFFFF,TileMode.CLAMP);
paint.setShader(着色);
paint.setXfermode(新PorterDuffXfermode(Mode.DST_IN));
canvas.drawRect(0,高度,宽度,bitmapWithReflection.getHeight()
+ reflectionGap,油漆);
返回bitmapWithReflection;
}
/ *
*(非Javadoc中)
*
* @see android.widget.Adapter#getCount将()
* /
@覆盖
公众诠释getCount将(){
返回linkedAdapter.getCount();
}
公共位图toSephia(位图bmpOriginal){
INT宽度,高度,R,G,B,C,暗淡;
身高= bmpOriginal.getHeight();
宽度= bmpOriginal.getWidth();
INT深度= 20;
位图bmpSephia = Bitmap.createBitmap(宽度,高度,
Bitmap.Config.ARGB_8888);
帆布油画=新的Canvas(bmpSephia);
涂料粉刷=新的油漆();
嘉洛斯厘米=新嘉洛斯();
cm.setScale(.3f,.3f,.3f,1.0F);
ColorMatrixColorFilter F =新ColorMatrixColorFilter(厘米);
paint.setColorFilter(F);
canvas.drawBitmap(bmpOriginal,0,0,油漆);
为(中间体X = 0 X - 其中;宽度; X ++){
对于(INT Y = 0; Y<高度; Y ++){
C = bmpOriginal.getPixel(X,Y);
R = Color.red(C);
G = Color.green(C);
B = Color.blue(C);
暗淡=(R + G + B)/ 3;
R = G = B =暗淡;
R = R +(深* 2);
G = G +深度;
如果(R> 255){
R = 255;
}
如果(g取代; 255){
G = 255;
}
bmpSephia.setPixel(X,Y,Color.rgb(R,G,B));
}
}
返回bmpSephia;
}
公共位图ConvertToBlackAndWhite(位图sampleBitmap){
嘉洛斯bwMatrix =新嘉洛斯();
bwMatrix.setSaturation(0);
最后ColorMatrixColorFilter colorFilter =新ColorMatrixColorFilter(
bwMatrix);
位图rBitmap = sampleBitmap.copy(Bitmap.Config.ARGB_8888,真正的);
涂料粉刷=新的油漆();
paint.setColorFilter(colorFilter);
帆布myCanvas =新的Canvas(rBitmap);
myCanvas.drawBitmap(rBitmap,0,0,油漆);
返回rBitmap;
}
}
Is there any library available for Carousel animation of images as available in iphonehttp://cocoacontrols.com/platforms/ios/controls/icarousel
I have used cover flow but it is not giving effect like iCarousel in iphone,soIf some other tricks by which i can implement this please give meThanks
May Be using This Code You Find Look Like Carousal
Main CoverFlow Activity
package pl.polidea.coverflow;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
* The Class CoverFlowTestingActivity.
*/
public class CoverFlowActivity extends Activity {
private TextView textView;
BaseAdapter coverImageAdapter;
/*
* (non-Javadoc)
*
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
private int[] DEFAULT_RESOURCE_LIST = { R.drawable.img1, R.drawable.img2,
R.drawable.img3, R.drawable.img4, R.drawable.img5, R.drawable.img6,
R.drawable.img7, R.drawable.img8 };
private int[] DEFAULT_RESOURCE_LIST1 = { R.drawable.img1a,
R.drawable.img2a, R.drawable.img3a, R.drawable.img4a,
R.drawable.img5a, R.drawable.img6a, R.drawable.img7a,
R.drawable.img8a };
public static ArrayList<Imagedata> i11Set;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView) findViewById(this.getResources().getIdentifier(
"statusText", "id", "pl.polidea.coverflow"));
// note resources below are taken using getIdentifier to allow importing
// this library as library.
/*
* final CoverFlow coverFlow1 = (CoverFlow)
* findViewById(this.getResources().getIdentifier("coverflow", "id",
* "pl.polidea.coverflow")); setupCoverFlow(coverFlow1, false);
*/
final CoverFlow reflectingCoverFlow = (CoverFlow) findViewById(this
.getResources().getIdentifier("coverflowReflect", "id",
"pl.polidea.coverflow"));
setupCoverFlow(reflectingCoverFlow, true);
}
/**
* Setup cover flow.
*
* @param mCoverFlow
* the m cover flow
* @param reflect
* the reflect
*/
private void setupCoverFlow(final CoverFlow mCoverFlow,
final boolean reflect) {
try
{
i11Set = new ArrayList<Imagedata>();
for (int resourceId : DEFAULT_RESOURCE_LIST1) {
i11Set.add(new Imagedata(resourceId));
// Global.i11.add(new Imagedata(resourceId));
}
if (reflect) {
coverImageAdapter = new ReflectingImageAdapter(
new ResourceImageAdapter(this, i11Set), 3);
} else {
coverImageAdapter = new ResourceImageAdapter(this, i11Set);
}
mCoverFlow.setAdapter(coverImageAdapter, -1);
mCoverFlow.setSelection(3, true);
setupListeners(mCoverFlow);
}
catch(Exception e)
{
e.printStackTrace();
}
}
/**
* Sets the up listeners.
*
* @param mCoverFlow
* the new up listeners
*/
private void setupListeners(final CoverFlow mCoverFlow) {
mCoverFlow.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(final AdapterView<?> parent,
final View view, int position, final long id) {
try
{
i11Set = new ArrayList<Imagedata>();
for (int resourceId = 0; resourceId < DEFAULT_RESOURCE_LIST1.length; resourceId++) {
{
if (resourceId == position) {
i11Set.add(new Imagedata(
DEFAULT_RESOURCE_LIST[resourceId]));
} else {
i11Set.add(new Imagedata(
DEFAULT_RESOURCE_LIST1[resourceId]));
}
}
// Global.i11.add(new Imagedata(resourceId));
}
/*for (int resourceId : DEFAULT_RESOURCE_LIST) {
i11Set.add(new Imagedata(resourceId));
// Global.i11.add(new Imagedata(resourceId));
}*/
coverImageAdapter = new ReflectingImageAdapter(
new ResourceImageAdapter(CoverFlowActivity.this,
i11Set), 3);
mCoverFlow.setAdapter(coverImageAdapter, -1);
mCoverFlow.setSelection(position, true);
//coverImageAdapter.notifyDataSetChanged();
// mCoverFlow.invalidate();
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
mCoverFlow.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(final AdapterView<?> parent,
final View view, final int position, final long id) {
textView.setText("Item selected! : " + id);
/*
* coverImageAdapter = new ReflectingImageAdapter(new
* ResourceImageAdapter(CoverFlowActivity.this),position);
* coverImageAdapter.notifyDataSetChanged();
* mCoverFlow.setAdapter(coverImageAdapter,position);
* mCoverFlow.setSelection(position, true);
* mCoverFlow.invalidate();
*/
}
@Override
public void onNothingSelected(final AdapterView<?> parent) {
textView.setText("Nothing clicked!");
}
});
}
}
Coverflow.java
package pl.polidea.coverflow;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Transformation;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.SpinnerAdapter;
/**
* Cover Flow implementation.
*
*/
public class CoverFlow extends Gallery {
/**
* Graphics Camera used for transforming the matrix of ImageViews.
*/
private final Camera mCamera = new Camera();
/**
* The maximum angle the Child ImageView will be rotated by.
*/
private int mMaxRotationAngle = 60;
/**
* The maximum zoom on the centre Child.
*/
private int mMaxZoom = -220;
/**
* The Centre of the Coverflow.
*/
private int mCoveflowCenter;
/** The image height. */
private float imageHeight;
/** The image width. */
private float imageWidth;
/** The reflection gap. */
private float reflectionGap;
/** The with reflection. */
private boolean withReflection;
/** The image reflection ratio. */
private float imageReflectionRatio;
/**
* Gets the image height.
*
* @return the image height
*/
public float getImageHeight() {
return imageHeight;
}
/**
* Sets the image height.
*
* @param imageHeight
* the new image height
*/
public void setImageHeight(final float imageHeight) {
this.imageHeight = imageHeight;
}
/**
* Gets the image width.
*
* @return the image width
*/
public float getImageWidth() {
return imageWidth;
}
/**
* Sets the image width.
*
* @param imageWidth
* the new image width
*/
public void setImageWidth(final float imageWidth) {
this.imageWidth = imageWidth;
}
/**
* Gets the reflection gap.
*
* @return the reflection gap
*/
public float getReflectionGap() {
return reflectionGap;
}
/**
* Sets the reflection gap.
*
* @param reflectionGap
* the new reflection gap
*/
public void setReflectionGap(final float reflectionGap) {
this.reflectionGap = reflectionGap;
}
/**
* Checks if is with reflection.
*
* @return true, if is with reflection
*/
public boolean isWithReflection() {
return withReflection;
}
/**
* Sets the with reflection.
*
* @param withReflection
* the new with reflection
*/
public void setWithReflection(final boolean withReflection) {
this.withReflection = withReflection;
}
/**
* Sets the image reflection ratio.
*
* @param imageReflectionRatio
* the new image reflection ratio
*/
public void setImageReflectionRatio(final float imageReflectionRatio) {
this.imageReflectionRatio = imageReflectionRatio;
}
/**
* Gets the image reflection ratio.
*
* @return the image reflection ratio
*/
public float getImageReflectionRatio() {
return imageReflectionRatio;
}
public CoverFlow(final Context context) {
super(context);
this.setStaticTransformationsEnabled(true);
}
public CoverFlow(final Context context, final AttributeSet attrs) {
this(context, attrs, android.R.attr.galleryStyle);
}
public CoverFlow(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
parseAttributes(context, attrs);
this.setStaticTransformationsEnabled(true);
}
/**
* Get the max rotational angle of the image.
*
* @return the mMaxRotationAngle
*/
public int getMaxRotationAngle() {
return mMaxRotationAngle;
}
/**
* Sets the.
*
* @param adapter
* the new adapter
*/
public void setAdapter(final SpinnerAdapter adapter,int position) {
if (!(adapter instanceof AbstractCoverFlowImageAdapter)) {
throw new IllegalArgumentException("The adapter should derive from "
+ AbstractCoverFlowImageAdapter.class.getName());
}
final AbstractCoverFlowImageAdapter coverAdapter = (AbstractCoverFlowImageAdapter) adapter;
coverAdapter.setWidth(imageWidth);
coverAdapter.setHeight(imageHeight);
if (withReflection) {
final ReflectingImageAdapter reflectAdapter = new ReflectingImageAdapter(coverAdapter,position);
reflectAdapter.setReflectionGap(reflectionGap);
reflectAdapter.setWidthRatio(imageReflectionRatio);
reflectAdapter.setWidth(imageWidth);
reflectAdapter.setHeight(imageHeight * (1 + imageReflectionRatio));
super.setAdapter(reflectAdapter);
} else {
super.setAdapter(adapter);
}
}
/**
* Set the max rotational angle of each image.
*
* @param maxRotationAngle
* the mMaxRotationAngle to set
*/
public void setMaxRotationAngle(final int maxRotationAngle) {
mMaxRotationAngle = maxRotationAngle;
}
/**
* Get the Max zoom of the centre image.
*
* @return the mMaxZoom
*/
public int getMaxZoom() {
return mMaxZoom;
}
/**
* Set the max zoom of the centre image.
*
* @param maxZoom
* the mMaxZoom to set
*/
public void setMaxZoom(final int maxZoom) {
mMaxZoom = maxZoom;
}
/**
* Get the Centre of the Coverflow.
*
* @return The centre of this Coverflow.
*/
private int getCenterOfCoverflow() {
return (getWidth() - getPaddingLeft() - getPaddingRight()) / 2 + getPaddingLeft();
}
/**
* Get the Centre of the View.
*
* @return The centre of the given view.
*/
private static int getCenterOfView(final View view) {
return view.getLeft() + view.getWidth() / 2;
}
/**
* {@inheritDoc}
*
* @see #setStaticTransformationsEnabled(boolean)
*/
@Override
protected boolean getChildStaticTransformation(final View child, final 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 {
//child.setLayoutParams(new LayoutParams(100,100));
rotationAngle = (int) ((float) (mCoveflowCenter - childCenter) / childWidth * mMaxRotationAngle);
if (Math.abs(rotationAngle) > mMaxRotationAngle) {
rotationAngle = rotationAngle < 0 ? -mMaxRotationAngle : mMaxRotationAngle;
}
Log.d("rotation Angle",""+rotationAngle);
transformImageBitmap((ImageView) child, t, rotationAngle);
}
return true;
}
/**
* This is called during layout when the size of this view has changed. If
* you were just added to the view hierarchy, you're called with the old
* values of 0.
*
* @param w
* Current width of this view.
* @param h
* Current height of this view.
* @param oldw
* Old width of this view.
* @param oldh
* Old height of this view.
*/
@Override
protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) {
mCoveflowCenter = getCenterOfCoverflow();
super.onSizeChanged(w, h, oldw, oldh);
}
/**
* Transform the Image Bitmap by the Angle passed.
*
* @param imageView
* ImageView the ImageView whose bitmap we want to rotate
* @param t
* transformation
* @param rotationAngle
* the Angle by which to rotate the Bitmap
*/
private void transformImageBitmap(final ImageView child, final Transformation t, final int rotationAngle) {
mCamera.save();
final Matrix imageMatrix = t.getMatrix();
final int height = child.getLayoutParams().height;
final int width = child.getLayoutParams().width;
final int rotation = Math.abs(rotationAngle);
mCamera.translate(0.0f, 0.0f, 100.0f);
// As the angle of the view gets less, zoom in
if (rotation < mMaxRotationAngle) {
//child.setLayoutParams(new LayoutParams(200,200));
final float zoomAmount = (float) (mMaxZoom + rotation * 10.0);
mCamera.translate(0.0f, 0.0f, zoomAmount);
}
mCamera.rotateY(rotationAngle);
mCamera.getMatrix(imageMatrix);
imageMatrix.preTranslate(-(width / 2.0f), -(height / 2.0f));
imageMatrix.postTranslate((width / 2.0f), (height / 2.0f));
mCamera.restore();
}
/**
* Parses the attributes.
*
* @param context
* the context
* @param attrs
* the attrs
*/
private void parseAttributes(final Context context, final AttributeSet attrs) {
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CoverFlow);
try {
imageWidth = a.getDimension(R.styleable.CoverFlow_imageWidth, 480);
imageHeight = a.getDimension(R.styleable.CoverFlow_imageHeight, 320);
withReflection = a.getBoolean(R.styleable.CoverFlow_withReflection, false);
imageReflectionRatio = a.getFloat(R.styleable.CoverFlow_imageReflectionRatio, 0.2f);
reflectionGap = a.getDimension(R.styleable.CoverFlow_reflectionGap, 4);
setSpacing(-50);
} finally {
a.recycle();
}
}
/* @Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
boolean leftScroll = isScrollingLeft(e1, e2);
float velX;
if(leftScroll)
{
velX=500;
}
else
{
velX=-500;
}
return super.onFling(e1, e2, velX, velocityY);
}
private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2){
return e2.getX() > e1.getX();
}*/
}
ResourceImageAdapter
package pl.polidea.coverflow;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
/**
* This class is an adapter that provides images from a fixed set of resource
* ids. Bitmaps and ImageViews are kept as weak references so that they can be
* cleared by garbage collection when not needed.
*
*/
public class ResourceImageAdapter extends AbstractCoverFlowImageAdapter {
/** The Constant TAG. */
private static final String TAG = ResourceImageAdapter.class
.getSimpleName();
/** The Constant DEFAULT_LIST_SIZE. */
private static final int DEFAULT_LIST_SIZE = 20;
/** The Constant IMAGE_RESOURCE_IDS. */
private static final List<Integer> IMAGE_RESOURCE_IDS = new ArrayList<Integer>(
DEFAULT_LIST_SIZE);
/** The Constant DEFAULT_RESOURCE_LIST. */
private static final int[] DEFAULT_RESOURCE_LIST = { R.drawable.img1a,
R.drawable.img2a, R.drawable.img3a, R.drawable.img4a,
R.drawable.img5a, R.drawable.img6a, R.drawable.img7a,
R.drawable.img8a };
/** The bitmap map. */
private final Map<Integer, WeakReference<Bitmap>> bitmapMap = new HashMap<Integer, WeakReference<Bitmap>>();
private final Context context;
private Imagedata i1;
// private ArrayList<Imagedata> i11=new ArrayList<Imagedata>();
/**
* Creates the adapter with default set of resource images.
*
* @param context
* context
*/
public ResourceImageAdapter(final Context context,
ArrayList<Imagedata> i11get) {
super();
this.context = context;
setResources(i11get);
}
/**
* Replaces resources with those specified.
*
* @param resourceIds
* array of ids of resources.
*/
public final synchronized void setResources(ArrayList<Imagedata> resourceIds) {
/*
* IMAGE_RESOURCE_IDS.clear();
*
* for (final int resourceId : resourceIds) {
* IMAGE_RESOURCE_IDS.add(resourceId);
*
* Global.i11.add(new Imagedata(resourceId)); }
*/
// Global.i11.clear();
try
{
Global.i11=new ArrayList<Imagedata>();
Global.i11 = resourceIds;
Log.d("Size of i11", "" + Global.i11.size());
notifyDataSetChanged();
}
catch(Exception e)
{
e.printStackTrace();
}
}
/*
* (non-Javadoc)
*
* @see android.widget.Adapter#getCount()
*/
@Override
public synchronized int getCount() {
return Global.i11.size();
}
/*
* (non-Javadoc)
*
* @see pl.polidea.coverflow.AbstractCoverFlowImageAdapter#createBitmap(int)
*/
@Override
protected Bitmap createBitmap(final int position) {
Log.v(TAG, "creating item " + position);
final Bitmap bitmap = ((BitmapDrawable) context.getResources()
.getDrawable(Global.i11.get(position).getSetResourceId()))
.getBitmap();
bitmapMap.put(position, new WeakReference<Bitmap>(bitmap));
return bitmap;
}
}
globals
package pl.polidea.coverflow;
import java.util.ArrayList;
public class Global {
public static ArrayList<Imagedata> i11=new ArrayList<Imagedata>();
}
ImageData
package pl.polidea.coverflow;
public class Imagedata {
private int setResourceId;
public Imagedata()
{}
public Imagedata(int rid) {
super();
this.setResourceId=rid;
}
public int getSetResourceId() {
return setResourceId;
}
public void setSetResourceId(int setResourceId) {
this.setResourceId = setResourceId;
}
}
ReflectingImageAdapter
package pl.polidea.coverflow;
import android.R.color;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Shader.TileMode;
import android.util.Log;
/**
* This adapter provides reflected images from linked adapter.
*
* @author potiuk
*
*/
public class ReflectingImageAdapter extends AbstractCoverFlowImageAdapter {
/** The linked adapter. */
private final AbstractCoverFlowImageAdapter linkedAdapter;
/**
* Gap between the image and its reflection.
*/
private float reflectionGap;
/** The image reflection ratio. */
private float imageReflectionRatio;
public int id;
private int position=-1;
/**
* Sets the width ratio.
*
* @param imageReflectionRatio
* the new width ratio
*/
public void setWidthRatio(final float imageReflectionRatio) {
this.imageReflectionRatio = imageReflectionRatio;
}
/**
* Creates reflecting adapter.
*
* @param linkedAdapter
* adapter that provides images to get reflections
*/
public ReflectingImageAdapter(
final AbstractCoverFlowImageAdapter linkedAdapter, int id) {
super();
this.id=id;
this.linkedAdapter = linkedAdapter;
}
/**
* Sets the reflection gap.
*
* @param reflectionGap
* the new reflection gap
*/
public void setReflectionGap(final float reflectionGap) {
this.reflectionGap = reflectionGap;
}
/**
* Gets the reflection gap.
*
* @return the reflection gap
*/
public float getReflectionGap() {
return reflectionGap;
}
/*
* (non-Javadoc)
*
* @see pl.polidea.coverflow.AbstractCoverFlowImageAdapter#createBitmap(int)
*/
@Override
protected Bitmap createBitmap(int position) {
// this.position=position;
return createReflectedImages(linkedAdapter.getItem(position),position);
}
/**
* Creates the reflected images.
*
* @param originalImage
* the original image
* @return true, if successful
*/
public Bitmap createReflectedImages(Bitmap originalImage,int position) {
Bitmap sepia=null ;
// Log.d("Id is",""+id);
// Log.d("position is","position"+position);
/*if(id==position)
{*/
sepia=originalImage;
/*}
else
{
sepia = ConvertToBlackAndWhite(originalImage);
}*/
final int width = sepia.getWidth();
final int height = sepia.getHeight();
final Matrix matrix = new Matrix();
matrix.preScale(1, -1);
final Bitmap reflectionImage = Bitmap.createBitmap(sepia, 0,
(int) (height * imageReflectionRatio), width,
(int) (height - height * imageReflectionRatio), matrix, false);
final Bitmap bitmapWithReflection = Bitmap.createBitmap(width,
(int) (height + height * imageReflectionRatio),
Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmapWithReflection);
canvas.drawBitmap(sepia, 0, 0, null);
final Paint deafaultPaint = new Paint();
deafaultPaint.setColor(color.transparent);
canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
final Paint paint = new Paint();
final LinearGradient shader = new LinearGradient(0, sepia.getHeight(),
0, bitmapWithReflection.getHeight() + reflectionGap,
0x70ffffff, 0x00ffffff, TileMode.CLAMP);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
+ reflectionGap, paint);
return bitmapWithReflection;
}
/*
* (non-Javadoc)
*
* @see android.widget.Adapter#getCount()
*/
@Override
public int getCount() {
return linkedAdapter.getCount();
}
public Bitmap toSephia(Bitmap bmpOriginal) {
int width, height, r, g, b, c, gry;
height = bmpOriginal.getHeight();
width = bmpOriginal.getWidth();
int depth = 20;
Bitmap bmpSephia = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmpSephia);
Paint paint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setScale(.3f, .3f, .3f, 1.0f);
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
paint.setColorFilter(f);
canvas.drawBitmap(bmpOriginal, 0, 0, paint);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
c = bmpOriginal.getPixel(x, y);
r = Color.red(c);
g = Color.green(c);
b = Color.blue(c);
gry = (r + g + b) / 3;
r = g = b = gry;
r = r + (depth * 2);
g = g + depth;
if (r > 255) {
r = 255;
}
if (g > 255) {
g = 255;
}
bmpSephia.setPixel(x, y, Color.rgb(r, g, b));
}
}
return bmpSephia;
}
public Bitmap ConvertToBlackAndWhite(Bitmap sampleBitmap) {
ColorMatrix bwMatrix = new ColorMatrix();
bwMatrix.setSaturation(0);
final ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(
bwMatrix);
Bitmap rBitmap = sampleBitmap.copy(Bitmap.Config.ARGB_8888, true);
Paint paint = new Paint();
paint.setColorFilter(colorFilter);
Canvas myCanvas = new Canvas(rBitmap);
myCanvas.drawBitmap(rBitmap, 0, 0, paint);
return rBitmap;
}
}
这篇关于为Android木马库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!