Play a custom viewgroup--ring around the display picture effect

Source: Internet
Author: User
Tags cos sin

Today's time is a little tight, a company organized by the Texas hold ' em to play, I will not say anything more. Just look at the effect first:






Effect: Very simple is the center of the central image of the ring scattered!

Core Logic: Obviously, this time is designed to place sub-view location, basic and the previous blog technical point is basically consistent, but also adopted the form of custom viewgroup, let the container add sub-view, and then in the onlayuout inside the location of the sub-view.


Algorithm analysis: The first circle of the head: A total of eight head, each picture of the angle is 360/8 = 45 degrees. Then add the Cos to work out the x-coordinate sin to calculate the y-coordinate, and calculate the lower-left-right points by getting their width and height respectively. Can be placed on the position. The second circle of the Avatar is the same, but it is a change of the starting angle.

The following code is directly on:

 /**   Call this method directly outside
     * initialization operation
     * @param num     The number to display Volume
     * @param radius   The radius of the first lap that you define
     */
    public void init ( int num, int radius) {
        Mradius = radius;
        This.num = num;         for (int i = 0; i < num; i++) {
            if (i = = 0) ) {

                ImageView ImageView = new ImageView (GetContext ());
                AddView (view,measureutil.dip2px), measureutil.dip2px (90) );
           } else {
                Imagev Iew ImageView = new ImageView (GetContext ());
                Imageview.setimageresource (r.mipmap.ic_launcher);
                AddView (ImageView, measureutil.dip2px), measureutil.dip2p X (40));
           }
       }
   }


PS: Get the width and height of the control
@Override
protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {
Super.onmeasure (Widthmeasurespec, Heightmeasurespec);
Get container width and height
Sizewidth = Getmeasuredwidth ();
Sizeheight = Getmeasuredheight ();
}


PS: Core Code

@Override
protected void OnLayout (Boolean changed, int l, int t, int r, int b) {
Super.onlayout (changed, L, T, R, b);
for (int i = 0; i < num; i++) {
View child = Getchildat (i);
if (child! = null) {
if (i = = 0) {//middle large picture
MX = SIZEWIDTH/2;
StartX = MX;
MY = SIZEHEIGHT/2;
Starty = MY;
} else if (I >= 1 && i <= 8) {//large image around first circle picture
Angle
MAngle = * (i-1);
Calculates the X y-coordinate according to the formula, and mradius the radius defined for itself.
MX = (int) (SIZEWIDTH/2 + Math.Cos (Math.toradians (mAngle)) * Mradius);
MY = (int) (SIZEHEIGHT/2 + Math.sin (Math.toradians (mAngle)) * Mradius);
} else {//large image around 2nd circle picture
MAngle = * (i-9) +23;
MX = (int) (SIZEWIDTH/2 + Math.Cos (Math.toradians (MAngle)) * (Mradius + 150));
MY = (int) (SIZEHEIGHT/2 + Math.sin (Math.toradians (MAngle)) * (Mradius + 150));
}
Put a big picture in the middle
if (i = = 0) {
Child.layout (Mx-child.getwidth ()/2, My-child.getheight ()/2, MX + child.getwidth ()/2, MY + child.getheight ()/2) ;
} else {//other pictures
Translateanimation translateanimation = new Translateanimation (startx-mx,0,starty-my, 0);
Translateanimation.setduration (400);
Translateanimation.setfillafter (TRUE);
Child.setanimation (translateanimation);
Child.layout (Mx-child.getwidth ()/2, My-child.getheight ()/2, MX + child.getwidth ()/2, MY + child.getheight ()/2) ;
}
}
}
}


It's OK. In fact, it is very simple, next time I will write some custom view to share things for you. Already memory management, allocation, disclosure of knowledge, and so on. I hope we all learn from each other. Leave a message whenever you need








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.