Android之十三图片2D翻转

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>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值