Make Coverflow appear like a Horizontal Gallery Android -


i trying make coverflow below appear horizontal gallery. original file looks

enter image description here

there 3 classes

  1. the coverflow.class extends gallery

    public class coverflow extends gallery {  private camera mcamera = new camera(); private int mmaxrotationangle = 50; private int mmaxzoom = -380; private int mcoveflowcenter; private boolean malphamode = true; private boolean mcirclemode = false; public coverflow(context context) {     super(context);     this.setstatictransformationsenabled(true); } public coverflow(context context, attributeset attrs) {     super(context, attrs);     this.setstatictransformationsenabled(true); } public coverflow(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 boolean getcirclemode() {     return mcirclemode; } public void setcirclemode(boolean iscircle) {     mcirclemode = iscircle; } public boolean getalphamode() {     return malphamode; } public void setalphamode(boolean isalpha) {     malphamode = isalpha; } 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; } /**  * called during layout when size of view has changed. if  * added view hierarchy, you're called old  * values of 0.  *   * @param w  *            current width of view.  * @param h  *            current height of view.  * @param oldw  *            old width of view.  * @param oldh  *            old height of view.  */ protected void onsizechanged(int w, int h, int oldw, int oldh) {     mcoveflowcenter = getcenterofcoverflow();     super.onsizechanged(w, h, oldw, oldh); } /**  * transform image bitmap angle passed  *   * @param imageview  *            imageview imageview bitmap want rotate  * @param t  *            transformation  * @param rotationangle  *            angle rotate bitmap  */ 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);     mcamera.translate(0.0f, 0.0f, 100.0f);     // angle of view gets less, zoom in     if (rotation <= mmaxrotationangle) {         float zoomamount = (float) (mmaxzoom + (rotation * 1.5));         mcamera.translate(0.0f, 0.0f, zoomamount);         if (mcirclemode) {             if (rotation < 40)                 mcamera.translate(0.0f, 155, 0.0f);             else                 mcamera.translate(0.0f, (255 - rotation * 2.5f), 0.0f);         }         if (malphamode) {             ((imageview) (child)).setalpha((int) (255 - rotation * 2.5));         }     }     mcamera.rotatey(rotationangle);     mcamera.getmatrix(imagematrix);      imagematrix.pretranslate(-(imagewidth ), -(imageheight / 2));     imagematrix.posttranslate((imagewidth ), (imageheight / 2));      mcamera.restore(); } 

    }

the second class coverflowactivity class class

public class coverflowactivity extends activity {     /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate); //        setcontentview(r.layout.main);          coverflow cf = new coverflow(this);         imageadapter ia = new imageadapter(this);         cf.setadapter(ia);         cf.setanimationduration(1000);         setcontentview(cf);      }      public class imageadapter extends baseadapter {          private int[] mimgs = {                 r.drawable.img1,                 r.drawable.img2,                 r.drawable.img3,                 r.drawable.img4,                 r.drawable.img5,                 r.drawable.img6,                 r.drawable.img7,                 r.drawable.img8         };         context mcontext;          public imageadapter(context context) {             this.mcontext = context;         }         @override         public int getcount() {             return mimgs.length;         }          @override         public object getitem(int position) {             return position;         }          @override         public long getitemid(int position) {             return mimgs[position];          }          @override         public view getview(int position, view convertview, viewgroup parent) {             reflectionimage = new reflectionimage(mcontext);              i.setimageresource(mimgs[position]);             i.setlayoutparams(new coverflow.layoutparams(100, 100));             i.setscaletype(imageview.scaletype.center_inside);             bitmapdrawable drawable = (bitmapdrawable) i.getdrawable();             drawable.setantialias(true);              return i;         }          public float getscale(boolean focused, int offset) {             return math.max(0, 1f/(float)math.pow(2, math.abs(offset)));         }      } } 

and third activity reflected image below each image.

public class reflectionimage extends imageview {     //是否为reflection模式     private boolean mreflectionmode = true;     public reflectionimage(context context) {         super(context);     }     public reflectionimage(context context, attributeset attrs) {         super(context, attrs);         //取得原始图片的bitmap并重画         bitmap originalimage = ((bitmapdrawable)this.getdrawable()).getbitmap();         doreflection(originalimage);     }     public reflectionimage(context context, attributeset attrs,             int defstyle) {         super(context, attrs, defstyle);         bitmap originalimage = ((bitmapdrawable)this.getdrawable()).getbitmap();         doreflection(originalimage);     }     public void setreflectionmode(boolean isref) {         mreflectionmode = isref;     }     public boolean getreflectionmode() {         return mreflectionmode;     }     //偷懒了,只重写了setimageresource,和构造函数里面干了同样的事情     @override     public void setimageresource(int resid) {         bitmap originalimage = bitmapfactory.decoderesource(                 getresources(), resid);         doreflection(originalimage);         //super.setimageresource(resid);     }     private void doreflection(bitmap originalimage) {         final int reflectiongap = 4;                            //原始图片和反射图片中间的间距         int width = originalimage.getwidth();         int height = originalimage.getheight();          //反转         matrix matrix = new matrix();         matrix.prescale(1, -1);       //reflectionimage就是下面透明的那部分,可以设置它的高度为原始的3/4,这样效果会更好些         bitmap reflectionimage = bitmap.createbitmap(originalimage, 0,                 0, width, height, matrix, false);         //创建一个新的bitmap,高度为原来的两倍         bitmap bitmapwithreflection = bitmap.createbitmap(width, (height + height), config.argb_8888);         canvas canvasref = new canvas(bitmapwithreflection);          //先画原始的图片         canvasref.drawbitmap(originalimage, 0, 0, null);         //画间距         paint deafaultpaint = new paint();         canvasref.drawrect(0, height, width, height + reflectiongap, deafaultpaint);          //画被反转以后的图片         canvasref.drawbitmap(reflectionimage, 0, height + reflectiongap, null);         // 创建一个渐变的蒙版放在下面被反转的图片上面         paint paint = new paint();         lineargradient shader = new lineargradient(0,                 originalimage.getheight(), 0, bitmapwithreflection.getheight()                         + reflectiongap, 0x80ffffff, 0x00ffffff, tilemode.clamp);         // set paint use shader (linear gradient)         paint.setshader(shader);         // set transfer mode porter duff , destination in         paint.setxfermode(new porterduffxfermode(mode.dst_in));         // draw rectangle using paint our linear gradient         canvasref.drawrect(0, height, width, bitmapwithreflection.getheight()                 + reflectiongap, paint);       //调用imageview中的setimagebitmap         this.setimagebitmap(bitmapwithreflection);     } } 

i want make appears gallery images must have 4 dp margin , appear center image without effects. can please me achieve this.

please try this:

private int mmaxrotationangle = 0; 

and

coverflow cf = new coverflow(this);    cf.setspacing(-30); 

in coverflowactivity


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -