{"id":612,"date":"2013-07-13T11:55:24","date_gmt":"2013-07-13T03:55:24","guid":{"rendered":"http:\/\/www.yeetrack.com\/?p=612"},"modified":"2013-09-27T22:36:36","modified_gmt":"2013-09-27T14:36:36","slug":"android-tween%e5%8a%a8%e7%94%bb","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=612","title":{"rendered":"Android Tween\u52a8\u753b"},"content":{"rendered":"<p>Android\u7cfb\u7edf\u63d0\u4f9b\u4e24\u79cd\u52a8\u753b\uff1a\u4e00\u79cd\u662fTween\uff0c\u7528\u6765\u5b9e\u73b0\u89c6\u56fe\u7ec4\u4ef6\u7684\u79fb\u52a8\u3001\u653e\u5927\u7f29\u5c0f\u3001\u65cb\u8f6c\u53ca\u900f\u660e\u5ea6\u53d8\u5316\uff1b\u53e6\u4e00\u79cd\u662fFrame\u52a8\u753b\uff0c\u901a\u8fc7\u5207\u6362\u5e27\u6765\u5b9e\u73b0\uff0c\u548c\u7535\u5f71\u7c7b\u4f3c\u3002<\/p>\n<p>Tween\u7c7b\u5728<code>android.view.animation<\/code>\u5305\u4e2d\uff0c\u8fd9\u4e2a\u5305\u5305\u542b\u4e86\u4e00\u4e9b\u5e38\u7528\u7684\u52a8\u753b\u7c7b\uff1a<\/p>\n<ul>\n<li><strong>Animation<\/strong> \u52a8\u753b\u62bd\u8c61\u7c7b\uff0c\u662f\u4e2a\u57fa\u7c7b\uff0c\u5176\u4ed6\u51e0\u79cd\u7c7b\u90fd\u7ee7\u627f\u8be5\u7c7b\u3002<\/li>\n<li><strong>ScaleAnimation<\/strong> \u7528\u4e8e\u653e\u5927\u3001\u7f29\u5c0f\u7684\u52a8\u753b\u7c7b<\/li>\n<li><strong>AlphaAniamtion<\/strong> \u7528\u4e8e\u63a7\u5236\u900f\u660e\u5ea6\u53d8\u5316\u7684\u52a8\u753b\u7c7b<\/li>\n<li><strong>RotateAnimation<\/strong> \u7528\u4e8e\u63a7\u5236\u65cb\u8f6c\u53d8\u5316\u7684\u52a8\u753b\u7c7b<\/li>\n<li><strong>TranslateAnimation<\/strong> \u7528\u4e8e\u63a7\u5236\u4f4d\u7f6e\u53d8\u5316\u7684\u52a8\u753b\u7c7b<\/li>\n<li><strong>AnimationSet<\/strong> \u5b9a\u4e49\u52a8\u753b\u5408\u96c6\u7684\u7c7b\uff0c\u52a8\u753b\u5408\u6210<\/li>\n<li><strong>AnimationUtil<\/strong> \u52a8\u753b\u5de5\u5177\u7c7b<!--more--><\/li>\n<\/ul>\n<p>Tween\u53ef\u4ee5\u914d\u7f6e\u5728xml\u6587\u4ef6\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u786c\u7f16\u7801\u5230\u4ee3\u7801\u4e2d\uff08\u63a8\u8350\u914d\u7f6e\u5230xml\u6587\u4ef6\u4e2d\uff09\u3002<\/p>\n<h4>\u65b9\u6cd51: \u786c\u7f16\u7801\u5230\u6587\u4ef6\u4e2d<\/h4>\n<pre><code>package com.yeetrack.android.animation;\n\nimport android.app.Activity;\nimport android.os.Bundle;\nimport android.view.View;\nimport android.view.View.OnClickListener;\nimport android.view.animation.AlphaAnimation;\nimport android.view.animation.Animation;\nimport android.view.animation.RotateAnimation;\nimport android.view.animation.ScaleAnimation;\nimport android.view.animation.TranslateAnimation;\nimport android.widget.Button;\nimport android.widget.ImageView;\n\npublic class MainActivity extends Activity {\n\nprivate Button scaleButton;\nprivate Button alphaButton;\nprivate Button translateButton;\nprivate Button rotateButton;\n\nprivate ImageView imageView;\n@Override\n\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.activity_main);\n    scaleButton = (Button)findViewById(R.id.testScaleId);\n    alphaButton = (Button)findViewById(R.id.testAlphaId);\n    translateButton = (Button)findViewById(R.id.testTranslateId);\n    rotateButton = (Button)findViewById(R.id.testRotateId);\n    imageView = (ImageView)findViewById(R.id.imageView);\n    imageView.setImageResource(R.drawable.annie);\n\n    OnClickListener onClickLinstener = new OnClickListener() \n    {\n\n        @Override\n        public void onClick(View v) \n        {\n            \/\/ TODO Auto-generated method stub\n            switch(v.getId())\n            {\n            case R.id.testScaleId:\n                \/\/\u524d\u56db\u4e2a\u53c2\u6570\uff0c\u8868\u793a\u4ece\u65e0\u9650\u5c0f\u6269\u5927\u5230\u4e00\u500d\u5927\u5c0f\uff1b\u540e\u9762\u4e24\u4e2a0.1f\uff0c\u63a7\u5236\u7740\u589e\u957f\u7684\u70b9\n                Animation animation = new ScaleAnimation(0f, 1f, 0f, 1f, Animation.RELATIVE_TO_SELF, 0.1f, Animation.RELATIVE_TO_SELF, 0.1f);\n                animation.setDuration(3000);\n                imageView.startAnimation(animation);\n                break;\n            case R.id.testAlphaId:\n                Animation animation2 = new AlphaAnimation(0.1f, 1f);\n                animation2.setDuration(3000);\n                imageView.startAnimation(animation2);\n                break;\n            case R.id.testTranslateId:\n                Animation animation3 = new TranslateAnimation(10,  100, 10 ,100);\n                animation3.setDuration(3000);\n                imageView.startAnimation(animation3);\n                break;\n\n            case R.id.testRotateId:\n                \/\/\u4ece0\u5ea6\u9009\u88c5180\u5ea6\uff0c\u4e24\u4e2a0.5f\uff0c\u8868\u793a\u56f4\u7ed5\u81ea\u8eab\u4e2d\u70b9\u65cb\u8f6c\uff0c\u8fd9\u4e24\u4e2a\u70b9\u63a7\u5236\u7740\u65cb\u8f6c\u4e2d\u5fc3\n                Animation animation4 = new RotateAnimation(0f, 180f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);\n                animation4.setDuration(3000);\n                imageView.startAnimation(animation4);\n                break;\n            }\n\n        }\n    };\n\n    scaleButton.setOnClickListener(onClickLinstener);\n    alphaButton.setOnClickListener(onClickLinstener);\n    translateButton.setOnClickListener(onClickLinstener);\n    rotateButton.setOnClickListener(onClickLinstener);\n}\n\n}\n<\/code><\/pre>\n<h4>\u914d\u7f6e\u5230xml\u6587\u4ef6\u4e2d<\/h4>\n<p>\u63a8\u8350\u7684\u65b9\u6cd5\u662f\u914d\u7f6e\u5230\u5916\u90e8\u7684xml\u6587\u4ef6\u4e2d\uff0c\u8fd9\u6837\u548c\u4ee3\u7801\u5206\u79bb\uff0c\u65b9\u4fbf\u4ee5\u540e\u914d\u7f6e\u3002<\/p>\n<p>\u5728res\u76ee\u5f55\u4e0b\u65b0\u5efaanim\u6587\u4ef6\u5939\uff0c\u65b0\u5efa\u4e00\u4e2a<code>translate.xml<\/code>\u6587\u4ef6,\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;set xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"&gt;\n&lt;translate \n    android:fromXDelta=\"0\"\n    android:toXDelta=\"100\"\n    android:fromYDelta=\"0\"\n    android:toYDelta=\"100\"\n    android:duration=\"2000\" \/&gt;\n&lt;\/set&gt;\n<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u914d\u7f6e\u4e86\u5e73\u79fb\u7684\u52a8\u753b\uff0c\u4f7f\u7528\u52a8\u753b\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code>private Animation translateAnimation;\ntranslateAnimation = AnimationUtils.loadAnimation(this, R.anim.translate);\nimageView.startAnimation(translateAnimation); \n<\/code><\/pre>\n<p><code>ScaleAnimation<\/code>\u3001<code>AlphaAnimation<\/code>\u3001<code>RotateAnimation<\/code>\u4e5f\u662f\u4e00\u6837\u7684\u914d\u7f6e\u3002<\/p>\n<p><!-- This document was created with MarkdownPad, the Markdown editor for Windows (http:\/\/markdownpad.com) --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android\u7cfb\u7edf\u63d0\u4f9b\u4e24\u79cd\u52a8\u753b\uff1a\u4e00\u79cd\u662fTween\uff0c\u7528\u6765\u5b9e\u73b0\u89c6\u56fe\u7ec4\u4ef6\u7684\u79fb\u52a8\u3001\u653e\u5927\u7f29\u5c0f\u3001\u65cb\u8f6c\u53ca\u900f\u660e\u5ea6\u53d8\u5316\uff1b\u53e6\u4e00\u79cd\u662fFrame\u52a8\u753b\uff0c\u901a\u8fc7\u5207\u6362\u5e27\u6765\u5b9e\u73b0\uff0c\u548c\u7535\u5f71\u7c7b\u4f3c\u3002 Tween\u7c7b\u5728android.view.a&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[33],"tags":[43,7,16],"class_list":["post-612","post","type-post","status-publish","format-standard","hentry","category-coding","tag-android","tag-7","tag-16"],"views":2513,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/612","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=612"}],"version-history":[{"count":2,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/612\/revisions"}],"predecessor-version":[{"id":728,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/612\/revisions\/728"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}