Android to achieve mushroom Street shopping cart animation effect

Source: Internet
Author: User

Version: 1.0Date: 2014.8.6Copyright: © kince Reproduced in the sourceusers who have used Mushroom Street are basically aware of an animated effect added to the shopping cart, which is not specifically described here to download the experience. 1. Ideasnow think of two ways to achieve this effect, one is to use tween animation, a straightforward move, Mushroom Street is the use of such a method. The second is to use WindowManager to create a view and then move the view.
2. RealizeIn this paper, the method is implemented in the first way, then the method is used. Way One: Activity Code:
Package Com.kince.mogujie;import Android.app.activity;import Android.content.context;import Android.graphics.drawable.colordrawable;import Android.os.bundle;import Android.os.handler;import Android.view.gravity;import Android.view.layoutinflater;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.animation.animation;import Android.view.animation.animation.animationlistener;import Android.view.animation.animationutils;import Android.widget.imageview;import Android.widget.popupwindow;import Android.widget.RelativeLayout.LayoutParams; Import android.widget.textview;/** * @author kince * @category imitation mushroom Street Shopping cart animation effect using tween animation * @issue 1, the first time to perform the animation amplification effect is obvious, after the amplification effect is not obvious , Mushroom Street also has such a problem. * 2, pop-up Popubwindow deformation hope to know the friends of this area to inform * */public class Mainactivity extends Activity {private ImageView Manimimagevi Ew;private TextView mtextview;private TextView mnumtextview;private Animation manimation;private Popupwindow    Mpopupwindow;    private int goodsnum=0; @Overrideprotectedvoid OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.detail_frame _layout); Manimimageview = (ImageView) Findviewbyid (r.id.cart_anim_icon); Mtextview = (TextView) Findviewbyid ( R.ID.DETAIL_CART_BTN); Mnumtextview = (TextView) Findviewbyid (r.id.detail_shopping_new); Mtextview.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated method Stubmanimimageview.setvisibility (view.visible); manimimageview.startanimation (manimation);}); Manimation = Animationutils.loadanimation (this, r.anim.cart_anim); Manimation.setanimationlistener (new Animationlistener () {@Overridepublic void Onanimationstart (Animation Animation) {//TODO auto-generated method stub}@ overridepublic void Onanimationrepeat (Animation Animation) {//TODO auto-generated method stub} @Overridepublic void Onanimationend (Animation Animation) {//TODO auto-generated method Stubgoodsnum++;mnumtextview.settext (goodsnum+ ""); Manimimageview.setvisibility(view.invisible); Createpopbwindow (); Mpopupwindow.showatlocation (Manimimageview, gravity.center| Gravity.center_horizontal, 0, 0);}); New Handler (). postdelayed (New Runnable () {@Overridepublic void Run () {//TODO auto-generated method Stubmanimimageview.setvisibility (view.visible); manimimageview.startanimation (manimation);}}, 1500);} private void Createpopbwindow () {Layoutinflater inflater = (layoutinflater) getsystemservice (context.layout_inflater_ SERVICE); View Contentview = inflater.inflate (r.layout.cart_popup_layout, null); Contentview.setfocusable (true); Contentview.setfocusableintouchmode (true); Mpopupwindow = new Popupwindow (this); Mpopupwindow.setcontentview ( Contentview); mpopupwindow.setbackgrounddrawable (new Colordrawable (0x00000000)); Mpopupwindow.setwidth ( layoutparams.wrap_content); Mpopupwindow.setheight (layoutparams.wrap_content); mpopupwindow.setfocusable (true); Mpopupwindow.setoutsidetouchable (false); Mpopupwindow.setanimationstyle (R.style.anim_menu_bottombar);}}
Very simple nothing to say, is to open an animation, but in the comments I also mentioned that the generated Popupwindow show some problems, have to know friends can leave a message to inform. Look again.animation files used:Cart_anim.xml
<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" > <set> <scale android:duration= "android:fromxscale=" 1.0 "Android             Oid:fromyscale= "1.0" android:pivotx= "50.0%" android:pivoty= "50.0%" android:toxscale= "1.4" android:toyscale= "1.4"/> <scale android:duration= "android:fromxscale=" "1.4" android:fromyscale= "1.4" android:pivotx= "50.0%" android:pivoty= "50.0%" a ndroid:startoffset= "android:toxscale=" 1.0 "android:toyscale=" 1.0 "/> </set> < set> <translate android:duration= "android:fromxdelta=" 0.0 "Android:from" Ydelta= "0.0" android:startoffset= "android:toxdelta=" 75.0%p "android:toydelta="-109.9     9756%p "/> <alpha       android:duration= "Android:fromalpha=" 1.0 "android:startoffset=" android:t Oalpha= "0.1"/> <scale android:duration= "" "android:fromxscale=" 1.0 "Andro Id:fromyscale= "1.0" android:pivotx= "50.0%" android:pivoty= "50.0%" android:startoffset= "60 0 "android:toxscale=" 0.4 "android:toyscale=" 0.4 "/> </set></set>
is an animation set that performs a zoom before performing other animation effects.
3. Effect
4. Code
http://download.csdn.net/detail/wangjinyu501/7721429

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.