{"id":3943,"date":"2021-02-05T15:44:51","date_gmt":"2021-02-05T07:44:51","guid":{"rendered":"http:\/\/122.152.205.50\/wordpress\/?p=3943"},"modified":"2022-05-09T14:31:06","modified_gmt":"2022-05-09T06:31:06","slug":"view%e4%bd%93%e7%b3%bb%ef%bc%88%e4%b8%89%ef%bc%89%ef%bc%9aview%e7%9a%84","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=3943","title":{"rendered":"View\u4f53\u7cfb\uff08\u4e09\uff09\uff1a\u52a8\u753b"},"content":{"rendered":"<p><a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/liuwangshu.cn\/application\/view\/3-animation.html\">http:\/\/liuwangshu.cn\/application\/view\/3-animation.html<\/a>\uff08\u5218\u671b\u8212\uff09<\/p>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.51cto.com\/4259297\/1679852\">https:\/\/blog.51cto.com\/4259297\/1679852<\/a>\uff08\u6211\u81ea\u5df1\u572851CTO\u4e0a\u7684\u535a\u5ba2\uff09<\/p>\n<h3>\u6848\u4f8b\u4e00\uff1a\u4e0a\u4e0b\u79fb\u52a8<\/h3>\n<p>\u9009\u62e9\u6539\u53d8\u8981\u79fb\u52a8\u7684View\u7684marginTop\u6216\u8005marginBottom\u4f5c\u4e3a\u57fa\u51c6\u5c5e\u6027\uff0c\u8ba1\u7b97\u8d77\u6b62\u4f4d\u7f6e\u57fa\u51c6\u5c5e\u6027\u7684\u503c\uff0c\u518d\u901a\u8fc7\u5c5e\u6027\u52a8\u753b\u751f\u6210\u6e10\u53d8\u503c\uff0c\u6700\u540e\u901a\u8fc7setLayoutParams\u53bb\u6539\u53d8\u57fa\u51c6\u5c5e\u6027\uff0c\u4ece\u800c\u8fbe\u5230\u4e0a\u4e0b\u5e73\u79fb\u7684\u6548\u679c<\/p>\n<pre><code class=\"language-java line-numbers\"> \/**\n     * \u5e73\u6ed1\u7ad6\u76f4\u79fb\u52a8View\n     * @param view\n     * @param duration\n     * @param detY\n     *\/\n    public static void smoothMoveViewByY(View view,int duration,float detY,OnViewMoveVerticalResultListener onViewMoveVerticalResultListener){\n        ViewGroup.MarginLayoutParams layoutParams = (MarginLayoutParams) view.getLayoutParams();\n        float startBottomMargin = layoutParams.bottomMargin;\n        float endBottomMargin = startBottomMargin - detY;\n        ValueAnimator animator = ValueAnimator.ofFloat(startBottomMargin,endBottomMargin);\n        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {\n            @Override\n            public void onAnimationUpdate(ValueAnimator animation) {\n\n                float bottomMargin = (Float) animation.getAnimatedValue();\n                ViewGroup.MarginLayoutParams layoutParams = (MarginLayoutParams) view.getLayoutParams();\n                float lastBottomMargin = layoutParams.bottomMargin;\n                layoutParams.bottomMargin = (int) bottomMargin;\n                \/\/\u6539\u53d8\u4f4d\u7f6e\n                view.setLayoutParams(layoutParams);\n                float detYFromStart =  (bottomMargin - startBottomMargin);\n                float detYFromLastMove =  (bottomMargin - lastBottomMargin);\n                float percent = Math.abs(detYFromStart \/ detY);\n\n                if(onViewMoveVerticalResultListener != null){\n                    onViewMoveVerticalResultListener.onMove(-1 * detYFromStart,-1 * detYFromLastMove,detY,percent);\n                }\n            }\n        });\n        animator.addListener(new Animator.AnimatorListener() {\n            @Override\n            public void onAnimationStart(Animator animation) {\n\n            }\n\n            @Override\n            public void onAnimationEnd(Animator animation) {\n                if(onViewMoveVerticalResultListener != null){\n                    onViewMoveVerticalResultListener.onMoveFinish(animation);\n                }\n            }\n\n            @Override\n            public void onAnimationCancel(Animator animation) {\n\n            }\n\n            @Override\n            public void onAnimationRepeat(Animator animation) {\n\n            }\n        });\n        \/\/\u6301\u7eed\u65f6\u957f\n        animator.setDuration(duration);\n        animator.start();\n    }\n<\/code><\/pre>\n<h3>\u6848\u4f8b\u4e8c\uff1a\u65e0\u9650\u65cb\u8f6c<\/h3>\n<h4>\u5c5e\u6027\u52a8\u753b\u65e0\u9650\u65cb\u8f6c<\/h4>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/cloud.tencent.com\/developer\/article\/1941172\">https:\/\/cloud.tencent.com\/developer\/article\/1941172<\/a><br \/>\n\u65b9\u5f0f1\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">ImageView img = findViewById(R.id.img_src);\nObjectAnimator objectAnimator = ObjectAnimator.ofFloat(img, \"rotation\", 0, 359);\nobjectAnimator.setRepeatCount(ValueAnimator.INFINITE);\nobjectAnimator.setDuration(2000);\nobjectAnimator.setInterpolator(new LinearInterpolator());\nobjectAnimator.start();\n<\/code><\/pre>\n<p>\u65b9\u5f0f2\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">    RotateAnimation animation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);\n        animation.setFillAfter(true);\n        animation.setRepeatCount(Animation.INFINITE);\n        animation.setDuration(1000);\n        animation.setInterpolator(new LinearInterpolator());\n        img.setAnimation(animation);\n        animation.start();\n<\/code><\/pre>\n<button class=\"simplefavorite-button\" data-postid=\"3943\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>http:\/\/liuwangshu.cn\/application\/view\/3-animation. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[124],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/3943"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3943"}],"version-history":[{"count":6,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/3943\/revisions"}],"predecessor-version":[{"id":6259,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/3943\/revisions\/6259"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3943"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}