Android點贊動畫效果 ,點贊後加一,2種方法,①補間動畫②位移動畫,android2種
第一個動畫檔案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="750" 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檔案夾 anim檔案夾下面,建立第二個檔案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主activity 我是在fragment中使用,你就隨意吧。
...private ScrollView scrollView; // This is my container. Yours may be differentprivate 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) { btnZan.startAnimation(btnAnim); } }); Log.i(TAG, "View created"); return view; }
另一種demo做法。試用了線程。不推薦使用
public class applaudAnimation extends Activity implements OnClickListener { private Button button; private TextView textView; private android.view.animation.Animation animation; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.animation); animation = AnimationUtils.loadAnimation(this,R.anim.applaud_animation); button = (Button) findViewById(R.id.bt); button.setOnClickListener(this); textView = (TextView) findViewById(R.id.animation); } @Override public void onClick(View v) { if (v == button) { textView.setVisibility(View.VISIBLE); textView.startAnimation(animation); new Handler().postDelayed(new Runnable() { public void run() { textView.setVisibility(View.GONE); } }, 1000); } }} |
animation.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" > <Button android:id="@+id/bt" android:layout_width="40dip" android:layout_height="wrap_content" android:layout_centerInParent="true" android:gravity="center" android:text="贊" android:textColor="#000000" android:textSize="18dip" /> <TextView android:id="@+id/animation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:gravity="center" android:text="+1" android:textColor="#FF0000" android:textSize="18dip" android:visibility="gone" /> </RelativeLayout> |
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="0" android:fromYDelta="0" android:toYDelta="-50" android:duration="1000"/> <alpha android:fromAlpha="1.0" android:toAlpha="0.3" android:duration="1000"/></set> |
為何做flash時,在兩個主要畫面格之間插入補間動畫後,在補間動畫測試時會發生位移,而且最後發生突變
主要畫面格,顧名思義就是在這一幀上的圖形映像將會發生變化(大小、形狀、顏色、旋
轉、透明度等等)。之所以如你說的會發生位移,而且最後發生突變,就是應為第一幀
和最後一針兩者雖然是同一映像,但是兩者的位置不一樣造成的,可能是不小心時滑鼠
拖動了其中一個主要畫面格中映像。其實,只要選中其中的一個主要畫面格,右鍵複製主要畫面格,
再到另一個主要畫面格,右鍵粘貼即可,這樣就不會發生位移,也不會突然跳動。有問題,
線上解決。
flash動畫製作的幾種補間的比較?
動作補件 可以做位移、縮放等動畫,自動建立元件。
形狀補件 可以形狀變形類動畫,不需建立元件。