Animation and Nineoldandroid Project day02

Source: Internet
Author: User

I. Project ISSUES

1. When the Welcome screen is displayed, disable the back key


two. Project development function point:

1. Monitor Key events

overriding the OnKeyDown () method in activity

650) this.width=650; "style=" Width:604.43px;height:auto; "alt=" a8c27ceca75049c2ac85d0cefd777170 "src=" http:/ note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ a8c27ceca75049c2ac85d0cefd777170 "/>


2. Customizing themes to solve multiple versions of Android fragmentation

Purpose: The theme in 2.x is Notitlebar,

The theme in 4.x is Noactionbar

The mechanism for reading resources from the Android system:

There are multiple styles.xml in the Res directory of the APK.

when the APK runs in version 2.x, the Android system will read the values in the

Styles.xml

when the APK runs in version 4.x, the Android system will read the VALUES-V14

Styles.xml in the catalog

650) this.width=650; "style=" Width:158.93px;height:auto; "alt=" 1a5630c875c5456d85a3fff4132128c5 "src=" http:/ /note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ 1a5630c875c5456d85a3fff4132128c5 "/>

steps:

1) Create a new theme in the Values/styles.xml file

650) this.width=650; "style=" Width:378.56px;height:auto; "alt=" 1d35161b509f48699c5804adfd4e3919 "src=" http:/ note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ 1d35161b509f48699c5804adfd4e3919 "/>

2) Create a new parent topic in the Values/styles.xml file

650) this.width=650; "style=" Width:426.66px;height:auto; "alt=" 466fc885e012407f8491d346f9ae9f36 "src=" http:/ note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ 466fc885e012407f8491d346f9ae9f36 "/>

3) Create a new parent topic in the Values-v14/styles.xml file

650) this.width=650; "style=" Width:501.48px;height:auto; "alt=" 2507e10a17d044efb5e63bc582ee96b9 "src=" http:/ note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ 2507e10a17d044efb5e63bc582ee96b9 "/>

4) Configure a new theme for the Welcome page activity in the manifest file

650) this.width=650; "style=" Width:521.73px;height:auto; "alt=" 9a496ffceccf461e81862c431d039d3d "src=" http:/ note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ 9a496ffceccf461e81862c431d039d3d "/>

           

3. Animations

gif, Flash

principle: Several pictures are played in sequence and at a certain time interval (100 milliseconds)

GIF is not supported by default because of poor picture quality (8-bit graph, 256 colors)

    

animations that are supported in Android

3.1 frameanimation

function: Capable of implementing any complex animation

implementation steps:

1) Copy keyframe (frame)

2) New Android XML

Resource type:drawable

Root element:animation-list

650) this.width=650; "style=" Width:524px;height:auto; "alt=" 5665c9c9011b49139de5e81c02a88ed0 "src=" http://note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/BCBA43691A214EB9A6C41A9956C74262/ 5665c9c9011b49139de5e81c02a88ed0 "/>

3) Edit picture sequence and switch interval

650) this.width=650; "style=" Width:537.03px;height:auto; "alt=" e18606a007d14e28ad45ae5cf473257e "src=" HT tp://note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ e18606a007d14e28ad45ae5cf473257e "/>

Add OneShot property, animation plays only once

650) this.width=650; "style=" Width:319.34px;height:auto; "alt=" 6f9d0a8f79cd45719ecf8ae9aef2a740 "src=" HT tp://note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ 6f9d0a8f79cd45719ecf8ae9aef2a740 "/>

4) Get animated object animationdrawable, play

650) this.width=650; "style=" Width:528px;height:auto; "alt=" 40c9c0ab362f45638f2de16cadd4bc26 "src=" http: note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ 40c9c0ab362f45638f2de16cadd4bc26 "/>


Note: The number of frameanimation pictures is limited

real-world scenarios: within a local scope, use a small number of images to achieve animation

    

3.2 tweenanimation

principle: By changing the properties of the view

size, position, angle, transparency


3.2.1 Implementing Transparency Animation steps:

a) Create animated objects in code mode

650) this.width=650; "style=" Width:682.05px;height:auto; "alt=" aa909b01573a4b93ad34258c08af2307 "src=" http://note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/BCBA43691A214EB9A6C41A9956C74262/ aa909b01573a4b93ad34258c08af2307 "/>


b) Create an animated object in XML mode

650) this.width=650; "style=" Width:509px;height:auto; "alt=" 5a2e47b781db43168da6be59ca6c330a "src=" http:/ note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ 5a2e47b781db43168da6be59ca6c330a "/>

Edit Animation Content

650) this.width=650; "style=" Width:487.98px;height:auto; "alt=" 4b933b57d82942d5a90c2ff4a06737d9 "src=" http:/ note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ 4b933b57d82942d5a90c2ff4a06737d9 "/>

convert animation XML to animation object in code

650) this.width=650; "style=" Width:526px;height:auto; "alt=" e712fcccc2db41129d289b7301485c65 "src=" http:/ note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ E712fcccc2db41129d289b7301485c65 "/>

3.2.2 Scale Animation Configuration Mobile Animation Configuration  

650) this.width=650; "style=" Width:288.38px;height:auto; "alt=" 8d521686056d4dcba6df714ec01f18ca "src=" htt p://note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/8d 521686056d4dcba6df714ec01f18ca "/> 650) this.width=650; style=" Width:426.62px;height:auto; "alt=" C2fc21a59b4b455ab21d55e8185f3c1c "src=" http://note.youdao.com/yws/public/resource/ 088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/c2fc21a59b4b455ab21d55e8185f3c1c "/>

Rotate Animation Configuration 650) this.width=650; "style=" Width:423.12px;height:auto; "alt=" e928daa57c9b46658f5747edeb890774 "src=" http://note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/BCBA43691A214EB9A6C41A9956C74262/ e928daa57c9b46658f5747edeb890774 "/>


The width or height of a screen: 100%p


4. Quick way to register events

1) Add the OnClick property to the control in the layout

650) this.width=650; "style=" Width:455.43px;height:auto; "alt=" Fc3d989af91640498b7bf0490a9363fa "src=" http:/ note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ Fc3d989af91640498b7bf0490a9363fa "/>

2) Add a method with the name of the OnClick property value to the activity

650) this.width=650; "style=" Width:466.76px;height:auto; "alt=" 79d7725118484fcbace77be1d839859e "src=" http:/ note.youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ 79d7725118484fcbace77be1d839859e "/>

Note: Must be public, parameter must be view v


5. principle of open source project

Project is set as library and can be reused by other projects


6. nineoldandroid Project usage


properties animation     Property Animation
android3.x New

Question: Official does not support 2.x
Use open source project

7. Welcome Page
    controls used viewpager
    Libs/android-support-v4.jar
Implementation steps:
1) Add a Viewpager control to the layout
    Android.support.v4.view.ViewPager
    Tips: Enter Viewpager in the code, associate it in Import
2) Initialize all Viewpager pages, Use arraylist<view> to save the
3) code in the set adapter
    mpager.setadapter ()
4) override the Isviewfromobject () method
    return arg0 = = Arg1;
5) Override Instantiateitem () method
    View view = Mlist.get (position);
    Mpager.addview (view);
    return view;    
6) Override Destroyitem () method
    View view = Mlist . get (position);
    Mpager.removeview (view);

//Change the number of Viewpager caches,

The meaning of the parameter is that the left and right caches several
Mpager.setoffscreenpagelimit (3);




Java.lang.UnsupportedOperationException:Required method

Destroyitem is not overridden

attached: frequently asked questions

goal: Be able to solve all the explained FC issues


1. The Code references r compilation errors,

The reason: the wrong R was imported

650) this.width=650; "style=" Width:369px;height:auto; "alt=" 49cc45d546344d3b870c893abff99121 "src=" Http://note . youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ 49cc45d546344d3b870c893abff99121 "/>


2. Java.lang.RuntimeException:Unable to instantiate (instantiation) activity componentinfo{com.example.cw_0811/ Com.example.w_0811.MainActivity}: java.lang.ClassNotFoundException: com.example.w_0811.MainActivity


FC Reason: Run-time exception and error

How to view logs:

1) Pull to the bottom of the logcat and look up

650) this.width=650; "style=" Width:255px;height:auto; "alt=" 984f162e25194824b1410054ea412aeb "src=" Http://note . youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ 984f162e25194824b1410054ea412aeb "/>

Main is the thread name, which can be another

2) Find the exception type name:

650) this.width=650; "style=" Width:405px;height:auto; "alt=" 02a2630abc3d4748aa466cd0a8f42e67 "src=" Http://note . youdao.com/yws/public/resource/088e077f9af472c19e8f99579265d3a1/bcba43691a214eb9a6c41a9956c74262/ 02a2630abc3d4748aa466cd0a8f42e67 "/>

3) The reasons for the ClassNotFoundException are:

The code does not have this class, pay attention to carefully check the package name + class name


3. Java.lang.RuntimeException:Unable to start Activity componentinfo{org.yuchen.test/ Org.yuchen.test.MainActivity}: Java.lang. classcastexception: Android.widget.Button cannot is cast to Android.widget.ImageView


cause: Eclipse's ADT Bug

scene: Modify layout and less code changes

Solution: Project->clean



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.