Tween动画
1.在关闭电视机的时候,电视机中间都有一根白条瞬间关闭。
要实现这个效果其实就是利用Tween动画进行实现的。
动画的xml 文件是:
android:startOffset="" 利用这个属性可以实现动画执行的先后顺序
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:zAdjustment="top" > <scale
android:duration="5000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="0.003" />
<scale
android:duration="3000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="5000"
android:toXScale="0.0"
android:toYScale="0.3" /> <alpha
android:duration="3000"
android:fillAfter="true"
android:fillEnabled="true"
android:fromAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:startOffset="5000"
android:toAlpha="0" /> <rotate
android:fromDegrees="0.0"
android:toDegrees="360.0"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator"
android:duration="5000"
/> </set>
主界面的Activity
public class MainActivity extends Activity { private ImageView back , line; private Animation mAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
} private void initView() {
back = (ImageView)findViewById(R.id.img_back);
line = (ImageView)findViewById(R.id.img_line);
mAnimation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.tv_off);
mAnimation.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation animation) { } @Override
public void onAnimationRepeat(Animation animation) { } @Override
public void onAnimationEnd(Animation animation) { }
}); line.setVisibility(View.VISIBLE);
line.setAnimation(mAnimation);
// mAnimation.start(); } }
activity_main.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" > <ImageView
android:id="@+id/img_back"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black" /> <ImageView
android:id="@+id/img_line"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:visibility="gone"
/> </FrameLayout>