Android之十三图片2D翻转
2016-05-12 18:00
441 查看
Android之十三图片2D翻转
java代码
package com.example.fanzhuan; import android.os.Bundle; import android.app.Activity; import android.graphics.drawable.Animatable; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.ScaleAnimation; import android.widget.ImageView; import android.widget.Toast; public class MainActivity extends Activity { private ImageView imageA; private ImageView imageB; private ScaleAnimation sato=new ScaleAnimation(1, 0, 1, 1,Animation.RELATIVE_TO_PARENT,0.5f,Animation.RELATIVE_TO_PARENT, 0.5f); private ScaleAnimation sato1=new ScaleAnimation(0, 1, 1, 1,Animation.RELATIVE_TO_PARENT,0.5f,Animation.RELATIVE_TO_PARENT, 0.5f); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initview(); findViewById(R.id.root).setOnClickListener(new OnClickListener() { public void onClick(View v) { //TODO Auto-generated method stub if(imageA.getVisibility()==View.VISIBLE){ imageA.startAnimation(sato); Toast.makeText(MainActivity.this, "数值11111", Toast.LENGTH_LONG); }else imageB.startAnimation(sato); Toast.makeText(MainActivity.this, "数值22222", Toast.LENGTH_LONG); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } private void showImageA(){ imageA.setVisibility(View.VISIBLE); imageB.setVisibility(View.INVISIBLE); } private void showImageB(){ imageA.setVisibility(View.INVISIBLE); imageB.setVisibility(View.VISIBLE); } private void initview(){ imageA=(ImageView) findViewById(R.id.ivA); imageB=(ImageView)findViewById(R.id.ivB); showImageA(); sato.setDuration(500);//动画持续时间 sato1.setDuration(500); sato.setAnimationListener(new AnimationListener() { public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub if(imageA.getVisibility()==View.VISIBLE){ imageA.setAnimation(null); showImageB(); imageB.startAnimation(sato1); Toast.makeText(MainActivity.this, "数值333333", Toast.LENGTH_SHORT); }else { imageB.setAnimation(null); showImageA(); imageA.startAnimation(sato1); Toast.makeText(MainActivity.this, "数值44444", Toast.LENGTH_SHORT); } } }); } }Ui代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/root" tools:context=".MainActivity" > <ImageView android:id="@+id/ivA" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/shi" /> <ImageView android:id="@+id/ivB" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:src="@drawable/shishi" /> </RelativeLayout>
相关文章推荐
- Android实现系统关机
- Android 加载大图片是出现的 OutOfMemoryError问题
- Android符号表转换
- Android自定义控件1:自定义topBar
- android 开发ndk相关总结
- android 存储详解
- android 录音与播放录音 带根据音频大小动态效果
- android studio 编译项目时报错: Gradle 'XXX' project refresh failed
- Android 热补丁动态修复框架小结
- GitHub 优秀的 Android 开源项目
- svn提交项目的时候如何把新创建的文件也提交上去
- Android开发设计模式之——单例模式关于线程不安全问题处理
- Android Studio gradle 配置 多渠道打包
- Android开发设计模式之——单例模式关于线程不安全问题处理
- 从Handler+Message+Looper源码带你分析Android系统的消息处理机制
- Android-常用String字符串操作方法
- mac下 ffmpeg 编译到android平台(支持 frei0r)
- Android的VectorDrawable与AnimatedVectorDrawable
- Android自定义属性
- Android入门开发之Intent