Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android-animation – 用于放大和缩小android for imageview的动画大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在单击imageview时设置放大和缩小?我希望我的程序在用户点击imageview时做出反应必须在某种程度上变大,并且可以在该屏幕上移动imageview,有时它会在触摸时减小尺寸在屏幕上的任何地方.再次点击是恢复原始大小我该怎么办

解决方法

据我所知,有两种方法.

第一种方式:

在res中创建一个名为’anim’的新文件夹.比在里面创建一个xml文件,例如zoomin.xml.然后将以下代码放入其中.

<scale  xmlns:android="http://scheR_241_11845@as.android.com/apk/res/android"
  android:fromXScale="1" 
  android:toXScale="5" 
  android:fromYScale="1" 
  android:toYScale="5" 
  android:pivotX="50%" 
  android:pivotY="50%" 
  android:duration="1000" 
  android:fillAfter="true">
</scale>

一个用于缩小,但具有反转值.

<scale  xmlns:android="http://scheR_241_11845@as.android.com/apk/res/android"
  android:fromXScale="5" 
  android:toXScale="1" 
  android:fromYScale="5" 
  android:toYScale="1" 
  android:pivotX="50%" 
  android:pivotY="50%" 
  android:duration="1000" 
  android:fillAfter="true">
</scale>

您可以根据需要更改值.我认为它们是不言自明的.

现在在你的java代码中.

ImageView imageView = (imageView)findViewById(R.id.yourImageViewId);

Animation zoomin = AnimationUtils.loadAnimation(this,R.anim.zoomin);
Animation zoomout = AnimationUtils.loadAnimation(this,R.anim.zoomout);
imageView.setAnimation(zoomin);
imageView.setAnimation(zoomout);

现在你只需要跟踪哪个是当前状态.并为每个州执行以下代码行:

imageView.startAnimation(zoomin);

imageView.startAnimation(zoomout);

例如:

imageView.setOnClickListener(new OnClickListener(){
            public void onClick(View v) {
                if(!pressed) {
                    v.startAnimation(zoomin);
                    pressed = !pressed;
                } else {
                    v.startAnimation(zoomout);
                    pressed = !pressed;
                }
            }
        });

另一种方式在这里描述:http://developer.android.com/training/animation/zoom.html.

大佬总结

以上是大佬教程为你收集整理的android-animation – 用于放大和缩小android for imageview的动画全部内容,希望文章能够帮你解决android-animation – 用于放大和缩小android for imageview的动画所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。