动图我也不会放 效果就是一层一层扩散. 代码如下. <FrameLayout android:layout_width="match_parent" android:layout_height="250dp" android:id="@+id/ll_card" android:background="@color/orange" android:orientation="vertical"> <!--中间的imageView--> <ImageView android:id="@+id/iv_wave_1" android:layout_width="170dp" android:layout_height="150dp" android:layout_gravity="center" android:background="@drawable/shape_circle" /> <!--最外层imageView--> <ImageView android:id="@+id/iv_wave_2" android:layout_width="170dp" android:layout_height="150dp" android:layout_gravity="center" android:background="@drawable/shape_circle" /> <!--中心imageView--> <ImageView android:id="@+id/iv_wave" android:layout_width="170dp" android:layout_height="150dp" android:layout_gravity="center" android:background="@drawable/shape_circle"/> </FrameLayout>
在activity中加入以下代码:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setSupportActionBar(toolbar); setContentView(R.layout.activity_main); iv1 = (ImageView)findViewById(R.id.iv_wave_1); iv2 = (ImageView)findViewById(R.id.iv_wave_2); setAnim1(); setAnim2(); }
private void setAnim1() { AnimationSet as = new AnimationSet(true); //缩放动画,以中心从原始放大到1.4倍 ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 1.4f, 1.0f, 1.4f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f); //渐变动画 AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f); scaleAnimation.setDuration(800); scaleAnimation.setRepeatCount(Animation.INFINITE); alphaAnimation.setRepeatCount(Animation.INFINITE); as.setDuration(800); as.addAnimation(scaleAnimation); as.addAnimation(alphaAnimation); iv1.startAnimation(as); } private void setAnim2() { AnimationSet as = new AnimationSet(true); //缩放动画,以中心从1.4倍放大到1.8倍 ScaleAnimation scaleAnimation = new ScaleAnimation(1.4f, 1.8f, 1.4f, 1.8f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f); //渐变动画 AlphaAnimation alphaAnimation = new AlphaAnimation(0.5f, 0.1f); scaleAnimation.setDuration(800); scaleAnimation.setRepeatCount(Animation.INFINITE); alphaAnimation.setRepeatCount(Animation.INFINITE); as.setDuration(800); as.addAnimation(scaleAnimation); as.addAnimation(alphaAnimation); iv2.startAnimation(as); }