嗨,我在这里做一个应用程序我需要comapre图像backgrounds.when,图像背景不同意味着我需要翻转这些图像,图像背景相同意味着我需要停止动画。我尝试使用下面的代码,但我翻转图像。但我不知道如何停止那些图像翻转动画时图像背景相同的时间。在这里,我需要提供自定义背景,因此拍摄了3张图片的6张图片。请任何人帮助我....
filpanimatedexample .class:
public class filpanimatedexample extends Activity implements OnClickListener {
/** Called when the activity is first created. */
RelativeLayout layout,layout1;
ImageView imageViewFlip,imageViewOriginal,imageViewFlip1,imageViewOriginal1,imageViewFlip2,imageViewOriginal2;
FlipAnimator animator,animator1,animator2,animator3,animator4,animator5;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageViewOriginal = (ImageView) findViewById(R.id.imageView1);
imageViewFlip = (ImageView) findViewById(R.id.imageView2);
imageViewOriginal1 = (ImageView) findViewById(R.id.imageView3);
imageViewFlip1 = (ImageView) findViewById(R.id.imageView4);
imageViewOriginal2 = (ImageView) findViewById(R.id.imageView5);
imageViewFlip2 = (ImageView) findViewById(R.id.imageView6);
imageViewOriginal.setOnClickListener(this);
imageViewFlip.setOnClickListener(this);
imageViewOriginal1.setOnClickListener(this);
imageViewFlip1.setOnClickListener(this);
imageViewOriginal2.setOnClickListener(this);
imageViewFlip2.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==imageViewOriginal)
{
animator = new FlipAnimator(imageViewOriginal, imageViewFlip,
imageViewFlip.getWidth() / 2, imageViewFlip.getHeight() / 2);
if (imageViewOriginal.getVisibility() == View.GONE) {
animator.reverse();
}
imageViewOriginal.startAnimation(animator);
}
if(v==imageViewFlip)
{
animator1 = new FlipAnimator(imageViewFlip, imageViewOriginal,
imageViewOriginal.getWidth() / 2, imageViewOriginal.getHeight() / 2);
if (imageViewFlip.getVisibility() == View.GONE) {
animator1.reverse();
}
imageViewOriginal.startAnimation(animator1);
}
if(v==imageViewOriginal1)
{
animator2 = new FlipAnimator(imageViewOriginal1, imageViewFlip1,
imageViewFlip1.getWidth() / 2, imageViewFlip1.getHeight() / 2);
if (imageViewOriginal1.getVisibility() == View.GONE) {
animator2.reverse();
}
imageViewOriginal1.startAnimation(animator2);
}
if(v==imageViewFlip1)
{
animator3 = new FlipAnimator(imageViewFlip1, imageViewOriginal1,
imageViewOriginal1.getWidth() / 2, imageViewOriginal1.getHeight() / 2);
if (imageViewFlip1.getVisibility() == View.GONE) {
animator3.reverse();
}
imageViewOriginal1.startAnimation(animator3);
}
if(v==imageViewOriginal2)
{
animator4 = new FlipAnimator(imageViewOriginal2, imageViewFlip2,
imageViewFlip2.getWidth() / 2, imageViewFlip2.getHeight() / 2);
if (imageViewOriginal2.getVisibility() == View.GONE) {
animator4.reverse();
}
imageViewOriginal2.startAnimation(animator4);
}
if(v==imageViewFlip2)
{
animator5 = new FlipAnimator(imageViewFlip2, imageViewOriginal2,
imageViewOriginal2.getWidth() / 2, imageViewOriginal2.getHeight() / 2);
if (imageViewFlip2.getVisibility() == View.GONE) {
animator5.reverse();
}
imageViewOriginal2.startAnimation(animator5);
}
}
main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="70dp"
android:scaleType="centerInside"
android:src="@drawable/icon" >
</ImageView>
<ImageView
android:id="@+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="70dp"
android:scaleType="centerInside"
android:src="@drawable/icon11" >
</ImageView>
<ImageView
android:id="@+id/imageView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="180dp"
android:scaleType="centerInside"
android:src="@drawable/icon" >
</ImageView>
<ImageView
android:id="@+id/imageView4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="180dp"
android:scaleType="centerInside"
android:src="@drawable/icon11" >
</ImageView>
<ImageView
android:id="@+id/imageView5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="270dp"
android:scaleType="centerInside"
android:src="@drawable/icon3" >
</ImageView>
<ImageView
android:id="@+id/imageView6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="270dp"
android:scaleType="centerInside"
android:src="@drawable/icon11" >
</ImageView>
</RelativeLayout>
</RelativeLayout>
答案 0 :(得分:0)
尝试将Drawable更改为Bitmap对象
Bitmap bitmap = ...;
Bitmap bitmap1 = ...;
if(bitmap == bitmap2)
{
//Your Toasts
}
转换的一个例子:
Drawable myDraw = view.getBackground();
Bitmap bitmap = ((BitmapDrawable)myDraw).getBitmap();
答案 1 :(得分:0)
i1=(ImageView)findViewById(R.id.imageView1);
i2=(ImageView)findViewById(R.id.imageView2);
Drawable d=i1.getDrawable();
Drawable d1=i2.getDrawable();
if( d == d1){
Toast.makeText(Example.this, "hello", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(Example.this, "hai", Toast.LENGTH_SHORT).show();
}