简体   繁体   English

Android Wear能够支持动画吗

[英]Is Android Wear able to support animation

I am a new on Android Wear. 我是Android Wear的新手。 Currently I am working on a project which is neccessary to send notifications to rotate an image on the Android Wear. 目前,我正在从事一个项目,该项目需要发送通知以在Android Wear上旋转图像。 I have tried to google for any same codes but to no avail. 我试图用谷歌搜索任何相同的代码,但无济于事。

Understand that Android Wear does not support AnimationUtil api, does it mean that it cannot animate rotating images? 理解Android Wear不支持AnimationUtil API,是否意味着它不能为旋转的图像设置动画? If able to support, is it possible to show some sample codes here? 如果可以支持,是否可以在此处显示一些示例代码?

Thanks. 谢谢。

Why don't you use setRotation? 为什么不使用setRotation? I used this for the second hand in my Wear app (battery efficient too!). 我在Wear应用程序中第二手使用了此功能(电池效率也很高!)。

imgSeconds = (ImageView) findViewById(R.id.imgsecond);
imgSeconds.setRotation(seconds*6);

Yes, it's possible. 是的,有可能。 Add this code in your wear app's Activity. 将此代码添加到您的穿戴应用的“活动”中。

    public class Animate extends Activity
            {
    Animation rotate;

            @Override
                protected void onCreate(Bundle savedInstanceState)
             {
                    requestWindowFeature(Window.FEATURE_NO_TITLE);
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.animate);
           final WatchViewStub stub = (WatchViewStub) findViewById(R.id.mainmenu_viewstub);
            stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() 
             {
                @Override
                public void onLayoutInflated(WatchViewStub stub) 
                    {

                     rotate = = AnimationUtils.loadAnimation(Animate.this,
                                R.anim.rotate);

                    ImageView tip = (ImageView) findViewById(R.id.tip);


//Write the below line of code to animate image at the place where you are getting the //notification.
tip.startAnimation(rotate);
                    }

            });

            }
            }

rotate.xml rotate.xml

  <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <rotate android:fromDegrees="0"
            android:toDegrees="360"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="600"
            android:repeatMode="restart"
            android:repeatCount="infinite"
            android:interpolator="@android:anim/cycle_interpolator"/>

    </set>

Hope this will help you buddy.. Thanks.. 希望这对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM