1.波浪效果
<ripple xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:color="@color/colorAccent" tools:targetApi="lollipop"> <item> <shape android:shape="rectangle"> <solid android:color="@color/colorPrimary"/> shape> item> ripple>
2.Circular Reveal
View以圆形的形式展开
import android.animation.Animator; import android.animation.AnimatorInflater; import android.animation.StateListAnimator; import android.os.Build; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.ViewAnimationUtils; import android.view.animation.Animation; import android.view.animation.DecelerateInterpolator; import android.widget.ImageView; public class CircularRevealActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_circular_reveal); final ImageView rect=findViewById(R.id.rect); rect.setOnClickListener(new View.OnClickListener() { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void onClick(View view) { Animator animator= ViewAnimationUtils.createCircularReveal( rect,0,0,0, (float) Math.hypot(rect.getWidth(),rect.getHeight())); animator.setInterpolator(new DecelerateInterpolator()); //开始快 然后减速 animator.setDuration(2000); animator.start(); } }); final ImageView circle=findViewById(R.id.circle); circle.setOnClickListener(new View.OnClickListener() { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void onClick(View v) { Animator animator1=ViewAnimationUtils.createCircularReveal( circle,circle.getWidth()/2,circle.getHeight()/2,circle.getWidth(),0); animator1.setInterpolator(new DecelerateInterpolator()); animator1.setDuration(2000); animator1.start(); } }); } }
3.View State changes Animation
1.StateListAnimator
视图改变时的动画效果
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <set> <objectAnimator android:propertyName="rotationX" android:duration="2000" android:valueFrom="0" android:valueTo="360" android:valueType="floatType" /> set> item> <item android:state_pressed="false"> <set> <objectAnimator android:propertyName="rotationX" android:valueFrom="360" android:valueTo="0" android:duration="2000" android:valueType="floatType"/> set> item> selector>
2.animated-selector
类似帧动画的切换效果
使用如下系统属性设置切换状态
private static final int[] STATE_CHECKED = new int[]{ android.R.attr.state_active}; private static final int[] STATE_UNCHECKED = new int[]{};
MainAc
import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.annotation.RequiresApi; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.ImageView; /** * Created by YRC on 2017/11/5. */ public class AsActivity extends AppCompatActivity { private boolean mIsCheck; private static final int[] STATE_CHECKED = new int[]{ android.R.attr.state_active}; private static final int[] STATE_UNCHECKED = new int[]{}; private ImageView mImageView; @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.a_s); mImageView =findViewById(R.id.image); Drawable mDrawable = ContextCompat.getDrawable(this, R.drawable.fab); mImageView.setImageDrawable(mDrawable); } public void anim(View view) { if (mIsCheck) { mImageView.setImageState(STATE_UNCHECKED, true); mIsCheck = false; } else { mImageView.setImageState(STATE_CHECKED, true); mIsCheck = true; } } }
<animated-selector xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" tools:targetApi="lollipop"> <item android:id="@+id/state_on" android:state_active="true"> <bitmap android:src="@mipmap/ic_done_anim_030" /> item> <item android:id="@+id/state_off"> <bitmap android:src="@mipmap/ic_plus_anim_030" /> item> <transition android:fromId="@+id/state_on" android:toId="@+id/state_off"> <animation-list> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_000" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_001" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_002" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_003" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_004" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_005" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_006" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_007" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_008" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_009" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_010" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_011" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_012" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_013" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_014" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_015" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_016" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_017" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_018" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_019" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_020" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_021" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_022" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_023" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_024" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_025" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_026" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_027" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_028" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_029" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_plus_anim_030" /> item> animation-list> transition> <transition android:fromId="@+id/state_off" android:toId="@+id/state_on"> <animation-list> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_000" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_001" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_002" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_003" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_004" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_005" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_006" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_007" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_008" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_009" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_010" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_011" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_012" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_013" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_014" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_015" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_016" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_017" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_018" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_019" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_020" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_021" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_022" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_023" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_024" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_025" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_026" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_027" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_028" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_029" /> item> <item android:duration="16"> <bitmap android:src="@mipmap/ic_done_anim_030" /> item> animation-list> transition> animated-selector>