2013-05-11 45 views
3

對於如何創建Google Plus投票動畫,您有任何想法/參考嗎? 我認爲它有兩個動畫,一個用於按鈕(視圖),另一個用於視圖組。 任何建議,將不勝感激。謝謝。如何在Android上模擬Google Plus投票動畫

enter image description hereenter image description here

enter image description hereenter image description here

+0

看起來就像動畫集,翻譯和規模......與監聽器更改顏色和設置文本以及第一個動畫的結束。 – Ixx 2013-05-11 10:35:45

+0

我試過翻譯,但我可以得到的東西接近但不是G +光滑:( – Hesam 2013-05-11 10:52:52

+0

似乎翻譯+規模與週期插值器,然後當它完成時,動搖動畫開始整個視圖組。 – yrajabi 2013-05-11 11:41:36

回答

3

好了好消息是花幾個小時終於找到解決方案後。 這是我的代碼,希望將來可以幫助其他人。

下RES /阿尼姆1-創建第一xml文件(在我的情況btn_anim.xml):

<?xml version="1.0" encoding="utf-8"?> 

<set 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/decelerate_interpolator"> 

    <translate 
     android:fromXDelta="0.0" 
     android:fromYDelta="0.0" 
     android:toXDelta="0.0" 
     android:toYDelta="-75.0" 
     android:duration="350" 
     android:fillBefore="true" 
     android:fillAfter="true" /> 

    <scale 
     android:fromXScale="1.0" 
     android:fromYScale="1.0" 
     android:toXScale="1.05" 
     android:toYScale="1.0" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:duration="350" 
     android:fillBefore="true" 
     android:fillAfter="true"/> 
</set> 

2-下RES /動畫創建第二xml文件(在我的情況layout_anim.xml):

<?xml version="1.0" encoding="utf-8"?> 

<set 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/decelerate_interpolator"> 

    <scale 
     android:fromXScale="1.0" 
     android:fromYScale="1.0" 
     android:toXScale="0.95" 
     android:toYScale="0.95" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:duration="100" 
     android:fillBefore="true" 
     android:fillAfter="true"/> 

</set> 

3-在您的活動(或片段)添加這些代碼:

... 
private ScrollView scrollView; // This is my container. Yours may be different 
private Animation btnAnim; 
private Animation layoutAnim; 
... 

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

     // Getting context 
     context = getActivity().getApplicationContext(); 

     btnAnim = AnimationUtils.loadAnimation(context, R.anim.btn_anim); 
     btnAnim.setAnimationListener(new Animation.AnimationListener() { 
      @Override 
      public void onAnimationStart(Animation animation) { 

      } 

      @Override 
      public void onAnimationEnd(Animation animation) { 
       layoutAnim = AnimationUtils.loadAnimation(context, R.anim.layout_anim); 
       scrollView.startAnimation(layoutAnim); 
      } 

      @Override 
      public void onAnimationRepeat(Animation animation) { 

      } 
     }); 

     // create view 
     View view = inflater.inflate(R.layout.fragment_browse_single, container, false); 

     scrollView = (ScrollView) view.findViewById(R.id.scrollView); 

     myButton = (Button) view.findViewById(R.id.myButton); 
     myButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       btnFancy.startAnimation(btnAnim); 
      } 
     }); 

     Log.i(TAG, "View created"); 
     return view; 
    }