view system

drawable

view(textview,imageview ...)

viewgroup(relative layout,linearLayout ...)

-----------------------------------------------------------------

Hierarchical mode

canvas layering

view overlay (event delivery mechanism)

View event delivery mechanism

Events are dispatched through dispatchTouchEvent, (the full behavior of a touch includes (down move up))

1. The dispatchTouchEvent of the parent container will call onInterceptTouchEvent to ask whether to intercept

If the interception will call its own onTouchEvent, the event will no longer be distributed downward. (And subsequent events (move up, etc.) will not be dispatched directly to this view)

do not intercept

 

2. Repeat the above process by calling the dispatchTouchEvent of the child view.

 

3. Until the leaf node, the dispatchTouchEvent of the leaf node executes the onTouchEvent of the leaf node

If onTouchEvent returns true, dispatchTouchEvent also returns true. Events are consumed and events are no longer delivered.

If onTouchEvent returns false, dispatchTouchEvent also returns false.

 

4. The parent view calls other dispatchTouchEvent related to the child view, if all return false, execute the parent's onTouchEvent.

 

Note: The down event of the leaf node onTouchEvent returns false and the subsequent events will not come again (the parent will generally not intercept the down, because the move and up will not reach the child after interception)

 

The problem of sliding conflict is actually that the child's view consumes the event and the parent view cannot get this event.

The solution is to decide whether the parent view should intercept this event as needed.

http://www.cnblogs.com/linjzong/p/4191891.html

----------------------------------------------------------------

Refresh power

timer

delay

slide

 

frame animation

Property animation

view animation

---------------------------------------------------------------------------------------------------------------

type of animation

The animation in Android has frame animation, property animation (after 3.0) view animation,

frame animation

AnimationDrawable - <animation-list> (It is a kind of drawable, the corresponding xml can only be placed in the drawable folder, the other two are placed in the animation)

Property animation

ObjectAnimator - <objectAnimator> 

ValueAnimator - <animator>  

AnimatorSet - <set> (animation collection, several animations are played at the same time, or played sequentially)

view animation

AlphaAnimation - <alpha/> (transparency animation)

RotateAnimation - <rotate/> (rotate animation has a pivot)

ScaleAnimation - <scale/> (scale animation has a pivot)

TranslateAnimation - <translate/> (move animation)

AnimationSet - <set> (view animation collection, several animations are played at the same time, or played sequentially)

 

 

1. AnimationDrawable frame-by-frame animation (it is a kind of drawable, which is a sequential display of one picture, the disadvantage is that it generally occupies a large amount of memory) 

Defined in xml:

The corresponding tag is <animation-list> (it is a drawable so it can only be placed in the res/drawable folder)

animation-list property:  

visible: The initial visibility of the drawable, defaults to false.  

oneshot: Whether to play only once and stop on the last frame.  

variablePadding: Whether to change as its state changes. Default is false  

The item property in animation-list:  

drawable: the drawable resource referenced by the current frame  

duration: The time (in milliseconds) that the current frame is displayed 

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"  

    android:oneshot="true">  

    <item  

        android:drawable="@mipmap/ic_launcher"  

        android:duration="200" />  

    <item  

        android:drawable="@mipmap/ic_launcher"  

        android:duration="200" />  

    <item  

        android:drawable="@mipmap/ic_launcher"  

        android:duration="200" />  

</animation-list>   

AnimationDrawable animationDrawable = (AnimationDrawable) getResources().getDrawable(R.drawable.animation_drawable); 

imageView.setBackgroundResource(animationDrawable);  

animationDrawable.start();   

  

Code to define frame animation:  

animationDrawable = new AnimationDrawable();   

animationDrawable.addFrame(drawable1, 100);   

animationDrawable.addFrame(drawable2, 100);  

animationDrawable.addFrame(drawable3, 100);  

imageView.setBackgroundResource(animationDrawable);  

animationDrawable.start();  

  

 

2. Property animation (ValueAnimator, ObjectAnimator, AnimatorSet, ViewPropertyAnimator) (only after 3.0)

It is a series of changes of values. These values ​​can be int float color objects (this requires you to define your own estimator)), and the changed values ​​are then assigned to properties to form animations.

Common properties of view animation:

duration: animation duration.

startOffset: How long to start the animation delay.

repeatCount: The number of animation plays, the default is 0, -1 means infinite loop (in the infinite code, you need to end the animation yourself)

repeatMode: The default is to restart after each end, and reverse to return after each end.

valueType: The type xml of the changed value can only be intType floatType, colorType, pathType (used on ObjectAnimator).

valueFrom: The starting value.

valueTo: end value.

interpolator: The property is the animation interpolator  

accelerate_interpolator accelerate-animation interpolator  

decelerate_interpolator decelerate - animation interpolator  

accelerate_decelerate_interpolator accelerate-decelerate animation interpolator  

例如android:interpolator="@android:anim/accelerate_decelerate_interpolator"  

Set the executor to monitor  

valueAnimator.addListener(new Animator.AnimatorListener() {  

    @Override  

    public void onAnimationStart(Animator animation) {  

        

    }  

    @Override  

    public void onAnimationEnd(Animator animation) {  

  

    }  

    @Override  

    public void onAnimationCancel(Animator animation) {  

  

    }  

    @Override  

    public void onAnimationRepeat(Animator animation) {  

  

    }  

});

  

1. ValueAnimator value animation executor (is a series of changes in values, these values ​​are assigned to object properties to form animation)

Defined in xml: (The xml file defined in xml must be placed in the res/animator folder)

Corresponding tag <animtor>

<animator xmlns:android="http://schemas.android.com/apk/res/android"

          android:duration="1000"

          android:startOffset="1000"

          android:repeatCount="-1"

          android:repeatMode="reverse"

          android:valueType="intType"

          android:valueFrom="10"

          android:valueTo="100"/>

Animator animator= AnimatorInflater.loadAnimator(this,R.animator.my_animator);

valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {  

    @Override  

    public void onAnimationUpdate(ValueAnimator animation) {  

        float f = (Float) animation.getAnimatedValue();  

    }  

});

valueAnimator.start(); 

Defined in the code:

ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);//The value can be any number or two

valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {  

    @Override  

    public void onAnimationUpdate(ValueAnimator animation) {  

        float f = (Float) animation.getAnimatedValue();  

    }  

});

valueAnimator.start(); 

Can only be used in code:

object

ValueAnimator valueAnimator = ValueAnimator.ofObject(new TypeEvaluator<MyClass>(){

    @Override

    public String evaluate(float fraction, String MyClass, String MyClass) {

        return (MyClass) animation.getAnimatedValue();

    }

},new MyClass(),new MyClass());

valueAnimator.start();

Attribute value holder (multiple attribute changes can be implemented)

PropertyValuesHolder propertyValuesHolder1=PropertyValuesHolder.ofInt(String propertyName, int... values);

propertyValuesHolder1.setObjectValues(myObject);

The Keyframe type object consists of a time/value pair that defines the specified value at the specified time point

Keyframe ofInt(float fraction)//还需setValue(Object value)

Keyframe ofInt(float fraction, int value)

Each keyframe can also have its own interpolator, which controls the time animation behavior between the previous keyframe and this keyframe.

PropertyValuesHolder propertyValuesHolder2=PropertyValuesHolder.ofKeyframe(String propertyName, Keyframe... values)

propertyValuesHolder2.setObjectValues(myObject);

ValueAnimator valueAnimator = ValueAnimator.ofPropertyValuesHolder(propertyValuesHolder1,propertyValuesHolder2);

valueAnimator.start();

 

2. ObjectAnimator object animation executor (inheriting ValueAnimator), (object animation executor, directly change the properties (the properties to be changed must have set, get methods (if the original class does not have the original class can be wrapped)))

Defined in xml:

Corresponding tag <objectAnimator>

propertyName: The name of the property whose value is to be changed. (must have get, set methods)

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"

        android:propertyName="xxx"

        android:duration="1000"

        android:startOffset="1000"

        android:repeatCount="-1"

        android:repeatMode="reverse"

        android:valueType="intType"

        android:valueFrom="10"

        android:valueTo="100"/>

Animator animator= AnimatorInflater.loadAnimator(this,R.animator.my_animator);

animator.setTarget(object);

animator.start(); 

Defined in the code:

ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(view, "rotationX", 0.0F, 360.0F).setDuration(500); 

objectAnimator.start();

ObjectAnimator ofInt(Object target, String xPropertyName, String yPropertyName,Path path);//The two parameters need the path to be the coordinate point

ObjectAnimator ofMultiInt(Object target, String propertyName, Path path)

Can only be used in code:

object

ObjectAnimator objectAnimator = ObjectAnimator.ofObject(object,"propertyName",new TypeEvaluator<MyClass>(){

    @Override

    public String evaluate(float fraction, String MyClass, String MyClass) {

        return (MyClass) animation.getAnimatedValue();

    }

},new MyClass(),new MyClass());

objectAnimator.start();

attribute value holder

PropertyValuesHolder propertyValuesHolder1=PropertyValuesHolder.ofInt(String propertyName, int... values);

propertyValuesHolder1.setObjectValues(myObject);

The Keyframe type object consists of a time/value pair that defines the specified value at the specified time point

Keyframe ofInt(float fraction)//还需setValue(Object value)

Keyframe ofInt(float fraction, int value)

Each keyframe can also have its own interpolator, which controls the time animation behavior between the previous keyframe and this keyframe.

PropertyValuesHolder propertyValuesHolder2=PropertyValuesHolder.ofKeyframe(String propertyName, Keyframe... values)

propertyValuesHolder2.setObjectValues(myObject);

ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(Object object,PropertyValuesHolder... values);

objectAnimator.start();

 

3.AnimatorSet property dialog set

Defined in xml:

Corresponding tag <set>

ordering: Play together, play sequentially.

Interpolator: Interpolator

<set xmlns:android="http://schemas.android.com/apk/res/android">

    <objectAnimator

            android:propertyName="xxx"

            android:duration="1000"

            android:startOffset="1000"

            android:repeatCount="-1"

            android:repeatMode="reverse"

            android:valueType="intType"

            android:valueFrom="10"

            android:valueTo="100"/>

    <objectAnimator

            android:propertyName="yyy"

            android:duration="1000"

            android:startOffset="1000"

            android:repeatCount="-1"

            android:repeatMode="reverse"

            android:valueType="intType"

            android:valueFrom="10"

            android:valueTo="100"/>

</set>

Animator animator= AnimatorInflater.loadAnimator(this,R.animator.my_animator);

animator.setTarget(object);

animator.start();

Defined in the code:

AnimatorSet animatorSet=new AnimatorSet();

animatorSet.playSequentially(objectAnimator1,objectAnimator2);

animatorSet.start();

 

ViewPropertyAnimator view property animation (execute view animation with animator)

view.animate().alpha(1);//The initial value of the view layout changes to the specified value 1.

 

 

3.view动画(alpha,rotate,scale,translate,AnimationSet)

Common properties of view animation:  

duration: The attribute is the animation duration  

startOffset: how long to delay to start execution  

fillAfter: Whether to stay in the last frame after the animation ends.  

repeatCount="-1": the number of repetitions

repeatMode : The mode of animation replay, that is, from beginning to end, from beginning to end, or from beginning to end, from end to end

interpolator: The property is the animation interpolator  

accelerate_interpolator accelerate-animation interpolator  

decelerate_interpolator decelerate - animation interpolator  

accelerate_decelerate_interpolator accelerate-decelerate animation interpolator  

例如android:interpolator="@android:anim/accelerate_decelerate_interpolator"  

Note: The value of coordinates or width and height can be an absolute value or a proportional value of its own width or height (the value of the following without special instructions can be that the origin of the coordinate system used in these two forms is in the upper left corner of its own view. )

Animation can be set to monitor  

animation.setAnimationListener (new Animation.AnimationListener ()  

     @Override  

     public void onAnimationStart(Animation animation) {  

         // Executed when the animation starts  

     }  

     @Override  

     public void onAnimationEnd(Animation animation) {  

         // Executed when the animation ends  

     }  

     @Override  

     public void onAnimationRepeat(Animation animation) {  

         // Execute every time the animation repeats  

     }  

});   

  

alpha transparency animation

Defined in xml:

Corresponding tag <alpha> (this animation xml is placed in the res/anim folder) 

fromAlpha: The property is the transparency at the beginning of the animation (value is 0f-1f)  

toAlpha: The property is the transparency at the end of the animation 

<alpha xmlns:android="http://schemas.android.com/apk/res/android"  

    android:fromAlpha="0"  

    android:toAlpha="1" />  

Animation myAnimation = AnimationUtils.loadAnimation (this, R.anim.my_action); 

view.startAnimation (animation);

Defined in the code:

AlphaAnimation alphaAnimation=new AlphaAnimation(0.1f, 1.0f);

view.startAnimation (animation);

 

 

rotate animation

Defined in xml:

The corresponding tag is <rotate>

pivotX: the x-axis coordinate of the rotation axis  

pivotY: the y-axis coordinate of the rotation axis  

fromDegrees: The angle at the beginning of the animation (clockwise is positive, counterclockwise is negative. The value can be greater than 360, and the horizontal state is 0 degrees)    

toDegrees: the angles at the end of the animation  

<rotate xmlns:android="http://schemas.android.com/apk/res/android"  

    android:pivotX="50%"  

    android:pivotY="50%"  

    android:fromDegrees="0"  

    android:toDegrees="180" />  

Animation myAnimation = AnimationUtils.loadAnimation (this, R.anim.my_action); 

view.startAnimation (animation);

Defined in the code:

public RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue,int pivotYType, float pivotYValue)   

pivotYType, pivotYValue: Can take values ​​as Animation.ABSOLUTE (absolute), Animation.RELATIVE_TO_SELF (relative to itself), Animation.RELATIVE_TO_PARENT (relative to parent)  

view.startAnimation (animation);

  

  

scale size scaling animation

Defined in xml:

The corresponding tag is <scale>

pivotX: the x-axis coordinate of the rotation axis  

pivotY: the y-axis coordinate of the rotation axis  

fromXScale: the width at the beginning of the animation  

toXScale: the width at the end of the animation  

fromYScale: the height at the beginning of the animation  

toYScale: the height at the end of the animation 

<scale xmlns:android="http://schemas.android.com/apk/res/android"  

    android:pivotX="50%"  

    android:pivotY="50%"  

    android:fromXScale="0%"  

    android:toXScale="100%"  

    android:fromYScale="100%"  

    android:toYScale="100%"/>  

Animation myAnimation = AnimationUtils.loadAnimation (this, R.anim.my_action); 

view.startAnimation (animation);      

Defined in the code:

public ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)  

pivotYType, pivotYValue: Can take values ​​as Animation.ABSOLUTE (absolute), Animation.RELATIVE_TO_SELF (relative to itself), Animation.RELATIVE_TO_PARENT (relative to parent)  

view.startAnimation (animation); 

 

translate position transfer animation

Defined in xml:

The corresponding tag is <translate>

fromXDelta: The x coordinate of the upper left corner of the view where the animation starts  

toXDelta: the x coordinate of the upper left corner of the view at the end of the animation  

The y coordinate of the upper left corner of the view at the start of the fromYDelta animation  

toYDelta: The y coordinate of the upper left corner of the view at the end of the animation  

<translate xmlns:android="http://schemas.android.com/apk/res/android"  

    android:fromXDelta="0"  

    android:toXDelta="100"  

    android:fromYDelta="0"  

    android:toYDelta="100" />  

Animation myAnimation = AnimationUtils.loadAnimation (this, R.anim.my_action); 

view.startAnimation (animation); 

Defined in the code:

public TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue,int fromYType, float fromYValue, int toYType, float toYValue)  

view.startAnimation (animation); 

 

AnimationSet view animation collection

Defined in xml:

The corresponding tag is <set>

Interpolator: Interpolator

shareInterpolator: Default true. Whether the animations in the collection share an interpolator. If the children in the collection also have interpolators, the children's ones work.

<set xmlns:android="http://schemas.android.com/apk/res/android"  

    android:shareInterpolator="true">  

    <alpha />  

    <rotate />  

    <scale />  

    <translate />  

    <set>  

        ...  

    </set>  

</set> 

AnimationSet myAnimationSet = AnimationUtils.loadAnimation (this, R.anim.my_action); 

view.startAnimation (myAnimationSet); 

Defined in the code:  

AnimationSet set=new AnimationSet(true);   

set.addAnimation (alphaAnimation);   

set.addAnimation(rotateAnimation);   

set.addAnimation(scaleAnimation);   

set.addAnimation(translateAnimation);   

set.addAnimation (aSet);

view.startAnimation(set);

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326846994&siteId=291194637