Read the Hyman Teacher's video, it sounds a little confused, so I want to realize the implementation of the satellite menu to summarize. Long story short, here's a summary:
One, custom ViewGroup
1), Custom properties file
The definition of the property:
<attr name= "Position" >
<enum name= "left_top" value= "0"/>
<enum name= "Left_bottom" value= "1"/>
<enum name= "Right_top" value= "2"/>
<enum name= "Right_bottom" value= "3"/>
<enum name= "Center_bottom" value= "4"/>
</attr>
<attr name= "radius" format= "Dimension"/>
It is important to note how to associate a property file with a custom ViewGroup
Connect it through arcmenu , and Arcmenu is our custom ViewGroup
<declare-styleable name= "Arcmenu" >
<attr name= "position"/>
<attr name= "radius"/>
</declare-styleable>
2), use in Layout file
It is important to note that the use of namespaces
Xmlns:hyman= "Http://schemas.android.com/apk/res/com.example.arcmenu"
This is divided into two parts:
The first part is: http://schemas.android.com/apk/res/
The second part is: Com.example.arcmenu (this can have a custom ViewGroup package name in Androidmanifest.xml)
3), read in the custom control
Create a custom ViewGroup
public class Arcmenu extends ViewGroup
{
}
You can then follow the steps below to implement the appropriate method.
How to read Custom properties:
The first thing you need to get is a custom property
TypedArray TypedArray = Context.gettheme (). Obtainstyledattributes (Attrs, R.styleable.arcmenu, Defstyle, 0);
Then get the value of the custom property
int position = Typedarray.getint (r.styleable.arcmenu_position, Position_right_bottom);
4) about the layout of custom controls
Here I focus mainly on the layout of the main menu in the middle of the following position:
First get the length width of the main menu:
int width = mcbutton.getmeasuredwidth ();
int height = mcbutton.getmeasuredheight ();
To place the main menu in the middle of the screen:
Then his x-coordinate is L = getmeasuredwidth ()/2-WIDTH/2;
The Y coordinate is: t = getmeasuredheight ()-height;
Final layout
Mcbutton.layout (L, T, L + width, t + height);
The layout location of the sub-menu
T1 = (int) (Mradius * Math.sin (Math.pi/count * (i + 1)));
l1= (int) (Mradius * Math.Cos (Math.pi/count * (i + 1)));
Coordinates of the final sub-menu
L = getmeasuredwidth ()/2-WIDTH/2-L1;
t = getmeasuredheight ()-height-t2;
Sub-menu Layout
Child.layout (L, T, L + width, t + height);
4), set the rotation animation of the main button
The 0.5f of this side represents the coordinate position of the relative to self.
Rotateanimation anim = new Rotateanimation (start, End, Animation.relative_to_self, 0.5f,
Animation.relative_to_self, 0.5f);
Anim.setduration (duration);
Anim.setfillafter (TRUE);
View.startanimation (ANIM);
5), add translation animation for MenuItem (note here: When you set the main menu to close and open, note the location of the change)
if (Mcurrentstatus = = status.is_closed)
{
Trananim = new Translateanimation (Xflag * cl, 0, Yflag * ct, 0);
Childview.setclickable (TRUE);
Childview.setfocusable (TRUE);
}
Else
{
Trananim = new Translateanimation (0, Xflag * cl, 0, Yflag * ct);
Childview.setclickable (FALSE);
Childview.setfocusable (FALSE);
}
Trananim.setfillafter (TRUE);
Trananim.setduration (duration);
Trananim.setstartoffset ((i * +)/count);
Trananim.setanimationlistener (New Animationlistener ()
{
@Override
public void Onanimationstart (Animation Animation)
{
}
@Override
public void Onanimationrepeat (Animation Animation)
{
}
@Override
public void Onanimationend (Animation Animation)
{
if (Mcurrentstatus = = status.is_closed)
{
Childview.setvisibility (View.gone);
}
}
});
Rotateanimation Rotateanim = new Rotateanimation (0, 720, animation.relative_to_self, 0.5f,
Animation.relative_to_self, 0.5f);
Rotateanim.setduration (duration);
Rotateanim.setfillafter (TRUE);
Animset.addanimation (Rotateanim);
Animset.addanimation (Trananim);
Childview.startanimation (Animset);
Note here: Listen to the submenu of the animation listener events, when the end of the animation, you need to modify the state of its main menu.
6), to achieve MenuItem click Animation
This is about adding an overlay animation
First, create a motion album
Animationset animationset = new Animationset (true);
Next create zoom out, and gradient animations
Scaleanimation Scaleanim = new Scaleanimation (1.0f, 0.0f, 1.0f, 0.0f, Animation.relative_to_self, 0.5f,
Animation.relative_to_self, 0.5f);
Alphaanimation Alphaanim = new Alphaanimation (1f, 0.0f);
Finally add the animation to the animated album
Animationset.addanimation (Scaleanim);
Animationset.addanimation (Alphaanim);
Set the duration and status
Animationset.setduration (duration);
Animationset.setfillafter (TRUE);
The end result is as follows:
Android implements a custom satellite menu