关于点击红点,图标扇形出现的代码实现,贴上自己的代码
虽然还有很多需要优化的地方,但也算实现了这个功能,需要的童鞋可以参考下
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 { //创建数组存储图片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}; //创建列表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; } } } 觉得有用的话,记得采纳回答哟