首页 > 代码库 > Android 模仿电视机关闭界面
Android 模仿电视机关闭界面
Tween动画
1.在关闭电视机的时候,电视机中间都有一根白条瞬间关闭。
要实现这个效果其实就是利用Tween动画进行实现的。
动画的xml 文件是:
android:startOffset="" 利用这个属性可以实现动画执行的先后顺序
1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" 3 android:shareInterpolator="false" 4 android:zAdjustment="top" > 5 6 <scale 7 android:duration="5000" 8 android:fromXScale="1.0" 9 android:fromYScale="1.0"10 android:interpolator="@android:anim/accelerate_interpolator"11 android:pivotX="50%"12 android:pivotY="50%"13 android:toXScale="1.0"14 android:toYScale="0.003" />15 <scale16 android:duration="3000"17 android:fromXScale="1.0"18 android:fromYScale="1.0"19 android:interpolator="@android:anim/accelerate_interpolator"20 android:pivotX="50%"21 android:pivotY="50%"22 android:startOffset="5000"23 android:toXScale="0.0"24 android:toYScale="0.3" />25 26 <alpha27 android:duration="3000"28 android:fillAfter="true"29 android:fillEnabled="true"30 android:fromAlpha="1.0"31 android:interpolator="@android:anim/accelerate_interpolator"32 android:startOffset="5000"33 android:toAlpha="0" />34 35 <rotate 36 android:fromDegrees="0.0"37 android:toDegrees="360.0"38 android:pivotX="50%"39 android:pivotY="50%"40 android:fillAfter="true"41 android:interpolator="@android:anim/linear_interpolator"42 android:duration="5000"43 />44 45 </set>
主界面的Activity
1 public class MainActivity extends Activity { 2 3 private ImageView back , line; 4 5 private Animation mAnimation; 6 @Override 7 protected void onCreate(Bundle savedInstanceState) { 8 super.onCreate(savedInstanceState); 9 setContentView(R.layout.activity_main);10 initView();11 }12 13 private void initView() {14 back = (ImageView)findViewById(R.id.img_back);15 line = (ImageView)findViewById(R.id.img_line);16 mAnimation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.tv_off);17 mAnimation.setAnimationListener(new AnimationListener() {18 19 @Override20 public void onAnimationStart(Animation animation) {21 22 }23 24 @Override25 public void onAnimationRepeat(Animation animation) {26 27 }28 29 @Override30 public void onAnimationEnd(Animation animation) {31 32 }33 });34 35 line.setVisibility(View.VISIBLE);36 line.setAnimation(mAnimation);37 // mAnimation.start();38 39 }40 41 42 }
activity_main.xml:
1 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 tools:context=".MainActivity" > 6 7 <ImageView 8 android:id="@+id/img_back" 9 android:layout_width="match_parent"10 android:layout_height="match_parent"11 android:background="@color/black" />12 13 <ImageView14 android:id="@+id/img_line"15 android:layout_width="match_parent"16 android:layout_height="match_parent"17 android:background="@color/white" 18 android:visibility="gone"19 />20 21 </FrameLayout>
源码下载
Android 模仿电视机关闭界面
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。