How Android makes an iphone that image jitter animation effect (including button and EditText)

Source: Internet
Author: User

Give the button a shake effect, you can do this, set up the Anim folder under Res, create a Button_shake.xml

<?xml version= "1.0" encoding= "Utf-8"? ><rotate xmlns:android= "Http://schemas.android.com/apk/res/android"    android:duration= "android:fromdegrees="    -3 "    android:pivotx=" 100% "    android:pivoty=" 100% "    android:repeatcount= "Infinite"    android:repeatmode= "reverse"    android:todegrees= "3"/>

In the code add:

Final ImageButton button = (ImageButton) Findviewbyid (R.ID.BTN); Button.setonclicklistener (new View.onclicklistener () {@Overridepublic void OnClick (View v) {Animation shake = Animationutils.loadanimation (Animationtest.this, R.anim.button_shake); Shake.reset (); Shake.setfillafter (true); Button.startanimation (shake);});

Give the edittext a lateral jitter effect:

Write Anim files like this:

<?xml version= "1.0" encoding= "Utf-8"? ><translate xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:fromxdelta=" 0 "android:toxdelta=" android:duration= "1300" android:interpolator= "@anim/cycle"/ >

Cycle.xml mainly describes the animation accelerator:

<?xml version= "1.0" encoding= "Utf-8"?><!--animation from start to finish, the rate of change is the sine curve of a given number of cycles. --><cycleinterpolator xmlns:android= "http://schemas.android.com/apk/res/android" android:cycles= "/>"

The code can be loaded like this:

Final Button confirm = (Button) Findviewbyid (r.id.btn_confirm); Confirm.setonclicklistener (new View.onclicklistener () {@Overridepublic void OnClick (View v) {if (Custom_edittext.gettext (). toString (). Equals ("Jake")) {Toast.maketext ( Animationtest.this, "Welcome", Toast.length_long). Show (); Else{animation shake = Animationutils.loadanimation (Animationtest.this, r.anim.shake_x); custom_ Edittext.startanimation (shake);}});

Code can be downloaded in http://download.csdn.net/detail/baidu_nod/7616277

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.