When you define a view, use the paint canvas for some of the temperature, simple frame animation (animated a," dig the boy gif" by the way to mention onwindowfocuschanged)

Source: Internet
Author: User

Reprint please indicate the source: Wang 亟亟 's way of Daniel

Before in the process of painting mentioned the static rotation ah, scaling ah, panning and some other effects. The view of your own definition, of course, also has a dynamic effect, which is our animation. There are three kinds of commonly used

View Animation
Drawable Animation
Property Animation

This article is about simple drawable Animation.

What does drawable animation look like?

Frame animation, a picture of a piece. The scene of the animation of a single broadcast.

The effect is so that a frame of a frame of the picture camera playback, the effect of animation.

Who does?

It's easy to see that you can do these things with handle and then runonuithread, but the view provides this implementation. Then why not?

First, define an animated XML (Java code execution, here is an example of XML claim), and put it under the Drable folder

Here is the back and the positive do the right to put, inverted things.

Then define the content of the picture and the duration of the detailed playback

The following is an example of an inverted broadcast

<animation-list xmlns:android="Http://schemas.android.com/apk/res/android" android:oneshot="true">        <itemandroid:drawable= "@drawable/draw9"android:duration="500 "/>                    <itemandroid:drawable="@drawable/draw8"android:duration= "/>"                    <itemandroid:drawable="@drawable/draw7"android:duration="500" />                    <itemandroid:drawable= "@drawable/draw6"android:duration="500 "/>                    <itemandroid:drawable="@drawable/draw5"android:duration= "/>"                    <itemandroid:drawable="@drawable/draw4"android:duration="500" />                    <itemandroid:drawable= "@drawable/draw3"android:duration="500 "/>                    <itemandroid:drawable="@drawable/draw2"android:duration= "/>"                    <itemandroid:drawable="@drawable/draw1"android:duration="500" />                </animation-list>

Then use the button to open the animation, the end is OK is very simple

@Override public void OnClick (View v) {int flag = V. GetId();Anim = (animationdrawable) animimageview. Getdrawable();Switch (flag) {case R. ID. Startanim: Animimageview. Setimageresource(R. drawable. Positive_anim);Anim. Start();                 Break;Case R. ID. Toppleanim: Animimageview. Setimageresource(R. drawable. Back_anim);Anim. Start();                 Break;Case R. ID. Stopanim: Anim. Stop();                 Break;}    }

Stop talking about onwindowfocuschanged, before measuring the size of the picture has seen his figure. So what did he do in detail?

In fact, at the beginning of our activity, like OnStart, Onresume, OnCreate actually our entire page is not finished rendering, so that's why we can't get the length and width of the control.

This method is called when your activity is acquired.

@OverridepublicvoidonWindowFocusChanged(boolean hasFocus) {     // TODO Auto-generated method stub     super.onWindowFocusChanged(hasFocus);}

We know that Onresume is also called when the activity gets the screen focus. So what's the difference between the 2 people?

We experiment by using the code log to explain the difference.

  @Override    protected void Onresume() {Super. Onresume (); LOG.D ("--->onresume","Onresume"); }@Override     Public void onwindowfocuschanged(BooleanHasfocus) {Super. onwindowfocuschanged (Hasfocus); LOG.D ("-->onwindowfocuschanged","--->animactivity onwindowfocuschanged");if(Hasfocus)        {Anim.start (); }    }@Override    protected void OnPause() {Super. OnPause (); LOG.D ("--->onpause","OnPause"); }

When you enter activity

01 -  16 : 57 :  24.131  5129 -5129 /paintcanvasdemo.pro  .WJJ  .paintcanvasdemo  d/--->onresume:onresume01 -04  16 : 57 : 24.161  5129 -5129 /paintcanvasdemo . Pro  .wjj  .paintcanvasdemo  D /-->>onwindowfocuschanged:--->animactivity onwindowfocuschanged  

When home exits

01 -  16 : 58 :  33.581  5129 -5129 /paintcanvasdemo.pro  .WJJ  .paintcanvasdemo  d/--->onpause:onpause01 -04  16 : 58 : 33.601  5129 -5129 /paintcanvasdemo . Pro  .wjj  .paintcanvasdemo  D /-->>onwindowfocuschanged:--->animactivity onwindowfocuschanged  

Of course, there is also a onstop,onrestart,onstart. But just to have our activity produce a focal level of change he can be heard. The point is, he's already done 100% interactive logic, and part of the content is onresume here (not completely rendered).

Source code Address: Https://github.com/ddwhan0123/BlogSample/tree/master/PaintCanvasDemo

Remember to praise OH.

When you define a view, use the paint canvas for some of the temperature, simple frame animation (animated a,&quot; dig the boy gif&quot; by the way to mention onwindowfocuschanged)

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.