1

我是Android Wear的新手。目前,我正在開發一個需要發送通知以旋轉Android Wear上的圖像的項目。我試圖谷歌任何相同的代碼,但無濟於事。Android Wear是否能夠支持動畫

瞭解Android Wear不支持AnimationUtil api,是否意味着它無法爲旋轉圖像添加動畫效果?如果能夠支持,是否有可能在這裏顯示一些示例代碼?

謝謝。

回答

0

是的,這是可能的。 將此代碼添加到您的穿着應用的活動中。

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

<?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> 

希望這將幫助你哥們..謝謝..

+1

我試過這個樣品,但它仍然無法顯示我的磨損旋轉。順便說一句,我在模擬器上運行磨損,這有什麼關係嗎? – user3464646 2014-08-27 18:00:55

1

你爲什麼不使用setRotation?我用我的Wear應用程序中的第二隻手(電池效率太高!)。

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