關(guān)于點(diǎn)擊紅點(diǎn),圖標(biāo)扇形出現(xiàn)的代碼實(shí)現(xiàn),貼上自己的代碼
雖然還有很多需要優(yōu)化的地方,但也算實(shí)現(xiàn)了這個(gè)功能,需要的童鞋可以參考下
import?android.animation.AnimatorSet; import?android.animation.ObjectAnimator; import?android.app.Activity; import?android.os.Bundle; import?android.view.View; import?android.view.animation.BounceInterpolator; import?android.widget.ImageView; import?android.widget.Toast; import?java.util.ArrayList; import?java.util.List; public?class?MainActivity?extends?Activity?implements?View.OnClickListener?{ ????//創(chuàng)建數(shù)組存儲圖片id ????private?int[]?res?=?{R.id.imageView_a,?R.id.imageView_b,?R.id.imageView_c,?R.id.imageView_d, ????????????R.id.imageView_e,?R.id.imageView_f,?R.id.imageView_g,?R.id.imageView_h}; ????//創(chuàng)建列表list存儲圖片 ????private?List<ImageView>?imageViewList?=?new?ArrayList<ImageView>(); ????private?boolean?flag?=?true; ????private?float?angle; ????private?final?int?r?=?380; ????@Override ????protected?void?onCreate(Bundle?savedInstanceState)?{ ????????super.onCreate(savedInstanceState); ????????setContentView(R.layout.my_activity); ????????for?(int?i?=?0;?i?<?res.length;?i++)?{ ????????????ImageView?imageView?=?(ImageView)?findViewById(res[i]); ????????????imageView.setOnClickListener(this); ????????????imageViewList.add(imageView); ????????} ????} ????@Override ????public?void?onClick(View?v)?{ ????????switch?(v.getId())?{ ????????????case?R.id.imageView_a: ????????????????if?(flag)?{ ????????????????????startAnim(); ????????????????}?else?{ ????????????????????closeAnim(); ????????????????} ????????????????break; ????????????default: ????????????????Toast.makeText(MainActivity.this,?"clicked"?+?v.getId(),?Toast.LENGTH_SHORT).show(); ????????????????break; ????????} ????} ????private?void?startAnim()?{ ????????angle?=?(float)?Math.PI?/?(2?*?(res.length?-?2)); ????????for?(int?i?=?1;?i?<?res.length;?i++)?{ ????????????float?xLength?=?(float)?(r?*?Math.sin((i?-?1)?*?angle)); ????????????float?yLength?=?(float)?(r?*?Math.cos((i?-?1)?*?angle)); ????????????ObjectAnimator?animator1?=?ObjectAnimator.ofFloat(imageViewList.get(i), ????????????????????"translationX",?0F,?-xLength); ????????????ObjectAnimator?animator2?=?ObjectAnimator.ofFloat(imageViewList.get(i), ????????????????????"translationY",?0F,?-yLength); ????????????AnimatorSet?set?=?new?AnimatorSet(); ????????????set.playTogether(animator1,?animator2); ????????????set.setDuration(500); ????????????set.setInterpolator(new?BounceInterpolator()); ????????????set.setStartDelay(i?*?200); ????????????set.start(); ????????????flag?=?false; ????????} ????} ????private?void?closeAnim()?{ ????????angle?=?(float)?Math.PI?/?(2?*?(res.length?-?2)); ????????for?(int?i?=?1;?i?<?res.length;?i++)?{ ????????????float?xLength?=?(float)?(r?*?Math.sin((i?-?1)?*?angle)); ????????????float?yLength?=?(float)?(r?*?Math.cos((i?-?1)?*?angle)); ????????????ObjectAnimator?animator1?=?ObjectAnimator.ofFloat(imageViewList.get(i), ????????????????????"translationX",?-xLength,?0F); ????????????ObjectAnimator?animator2?=?ObjectAnimator.ofFloat(imageViewList.get(i), ????????????????????"translationY",?-yLength,?0F); ????????????AnimatorSet?set?=?new?AnimatorSet(); ????????????set.playTogether(animator1,?animator2); ????????????set.setDuration(500); ????????????set.setInterpolator(new?BounceInterpolator()); ????????????set.setStartDelay((res.length-i)?*?200); ????????????set.start(); ????????????flag?=?true; ????????} ????} } 覺得有用的話,記得采納回答喲
2016-06-30
這是效果圖