Android Sliding effect (vi) reflection effect

Source: Internet
Author: User
Tags reflection

The introduction of the use of animation to achieve 3D Animation rotation page effect, now introduce the image of the realization of reflection, first look at the effect chart

This sample is implemented primarily by customizing gallery and Imageadapter (inherited from Baseadapter)

1. Reflection Drawing

Imageadapter inherits from Baseadapter, detailed implementation of visible Android sliding effect Introduction (ii)--gallery here focus on the reflection principle and realization

Reflection principle:

Reflection effect is mainly from the original image + spacing + reflection of the three parts, the height of about 3/2 of the original image (the original image is 1, the reflection is 1/2)

The original image, is that we saw the beginning of the picture

Spacing, is the original image and reflection between the gap, such as: Reflectiongap = 4;

The reflection is the lower half of the original image 1/2 height, through the Matrix transformation Matrix.prescale (1,-1); Get an inverted picture and then add a linear mask and shadow implementation

Reflection realization:

/** Reflection Reflection * * Public boolean createreflectedimages () {final int reflectiongap = 4;     
    int index = 0;     
        For (map<string, object> map:list) {Integer id = (integer) map.get ("image");   Bitmap originalimage = Bitmapfactory.decoderesource (Mcontext.getresources (), id);     
        Get the original picture int width = Originalimage.getwidth ();     
         
        int height = originalimage.getheight ();     
        Matrix matrix = new Matrix ();         Matrix.prescale (1,-1); Picture matrix Transformation (reflection from the lower part to the top) Bitmap reflectionimage = Bitmap.createbitmap (originalimage, 0, HEIGHT/2, width, HEIGHT/2   , Matrix, false); Intercept the lower part of the original Bitmap bitmapwithreflection = Bitmap.createbitmap (width, (height + height/2), config.argb_8888)          ;   Create a reflection picture (height is original 3/2) Canvas Canvas = new Canvas (bitmapwithreflection);       Draw Reflection (original image + spacing + reflection) Canvas.drawbitmap (originalimage, 0, 0, NULL); Drawing artwork    
        Paint Paint = new Paint ();       Canvas.drawrect (0, height, width, height + reflectiongap, paint);    Draw the spacing between the original image and the reflection Canvas.drawbitmap (reflectionimage, 0, height + reflectiongap, null);     
        Draw Reflection Map Paint = new paint (); LinearGradient shader = new LinearGradient (0, Originalimage.getheight (), 0, bitmapwithreflection.getheight () +     
        Reflectiongap, 0x70ffffff, 0X00FFFFFF, Tilemode.clamp);    Paint.setshader (shader);     Linear gradient effect Paint.setxfermode (new Porterduffxfermode (mode.dst_in));     Shadow mask Effect canvas.drawrect (0, height, width, bitmapwithreflection.getheight () + reflectiongap, paint);     
        Draw the shadow effect of the reflection imageview ImageView = new ImageView (mcontext);     Imageview.setimagebitmap (bitmapwithreflection);     
        Set the reflection Picture Imageview.setlayoutparams (New Mygallery.layoutparams (180, 240));     
    Imageview.setscaletype (Scaletype.matrix);    mimages[index++] = ImageView;     
return true; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.