要实现图片缩小放大的动画,可以参考下面的flow
首先定义小图片和大图片的容器
如下code所示小图片是是ImageButton来实现,大图片是用ImageView来实现.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="16dp">

<ImageButton
            android:id="@+id/thumb_button_1"
            android:layout_width="100dp"
            android:layout_height="75dp"
            android:layout_marginRight="1dp"
            android:src="@drawable/thumb1"
            android:scaleType="centerCrop"
            android:contentDescription="@string/description_image_1" />

</LinearLayout>

<!-- This initially-hidden ImageView will hold the expanded/zoomed version of
         the images above. Without transformations applied, it takes up the entire
         screen. To achieve the "zoom" animation, this view's bounds are animated
         from the bounds of the thumbnail button above, to its final laid-out
         bounds.
         -->

<ImageView
        android:id="@+id/expanded_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="invisible"
        android:contentDescription="@string/description_zoom_touch_close" />

</FrameLayout>

下来实现一个fragment 来监听用户的点击事件来实现zoom动画.
public class ZoomActivity extends FragmentActivity {
    // Hold a reference to the current animator,
    // so that it can be canceled mid-way.
    private Animator mCurrentAnimator;

// The system "short" animation time duration, in milliseconds. This
    // duration is ideal for subtle animations or animations that occur
    // very frequently.
    private int mShortAnimationDuration;

@Override调用
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zoom);

// Hook up clicks on the thumbnail views.

final View thumb1View = findViewById(R.id.thumb_button_1);
        thumb1View.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                zoomImageFromThumb(thumb1View, R.drawable.image1);
            }
        });

// Retrieve and cache the system's default "short" animation time.
        mShortAnimationDuration = getResources().getInteger(
                android.R.integer.config_shortAnimTime);
    }
    ...
}
当用户点击的时候会出的onClick调用zoomImageFromThumb
private void zoomImageFromThumb(final View thumbView, int imageResId) {
    // If there's an animation in progress, cancel it
    // immediately and proceed with this one.
    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();
    }

// Load the high-resolution "zoomed-in" image.
    final ImageView expandedImageView = (ImageView) findViewById(
            R.id.expanded_image);
    expandedImageView.setImageResource(imageResId);

// Calculate the starting and ending bounds for the zoomed-in image.
    // This step involves lots of math. Yay, math.
    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

// The start bounds are the global visible rectangle of the thumbnail,
    // and the final bounds are the global visible rectangle of the container
    // view. Also set the container view's offset as the origin for the
    // bounds, since that's the origin for the positioning animation
    // properties (X, Y).
    thumbView.getGlobalVisibleRect(startBounds);
    findViewById(R.id.container)
            .getGlobalVisibleRect(finalBounds, globalOffset);
    startBounds.offset(-globalOffset.x, -globalOffset.y);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);

// Adjust the start bounds to be the same aspect ratio as the final
    // bounds using the "center crop" technique. This prevents undesirable
    // stretching during the animation. Also calculate the start scaling
    // factor (the end scaling factor is always 1.0).
    float startScale;
    if ((float) finalBounds.width() / finalBounds.height()
            > (float) startBounds.width() / startBounds.height()) {
        // Extend start bounds horizontally
        startScale = (float) startBounds.height() / finalBounds.height();
        float startWidth = startScale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        // Extend start bounds vertically
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }

// Hide the thumbnail and show the zoomed-in view. When the animation
    // begins, it will position the zoomed-in view in the place of the
    // thumbnail.
    thumbView.setAlpha(0f);
    expandedImageView.setVisibility(View.VISIBLE);

// Set the pivot point for SCALE_X and SCALE_Y transformations
    // to the top-left corner of the zoomed-in view (the default
    // is the center of the view).
    expandedImageView.setPivotX(0f);
    expandedImageView.setPivotY(0f);

// Construct and run the parallel animation of the four translation and
    // scale properties (X, Y, SCALE_X, and SCALE_Y).
    AnimatorSet set = new AnimatorSet();
    set
            .play(ObjectAnimator.ofFloat(expandedImageView, View.X,
                    startBounds.left, finalBounds.left))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.Y,
                    startBounds.top, finalBounds.top))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X,
            startScale, 1f)).with(ObjectAnimator.ofFloat(expandedImageView,
                    View.SCALE_Y, startScale, 1f));
    set.setDuration(mShortAnimationDuration);
    set.setInterpolator(new DecelerateInterpolator());
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
        }

@Override
        public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
        }
    });
    set.start();
    mCurrentAnimator = set;

// Upon clicking the zoomed-in image, it should zoom back down
    // to the original bounds and show the thumbnail instead of
    // the expanded image.
    final float startScaleFinal = startScale;
    expandedImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mCurrentAnimator != null) {
                mCurrentAnimator.cancel();
            }

// Animate the four positioning/sizing properties in parallel,
            // back to their original values.
            AnimatorSet set = new AnimatorSet();
            set.play(ObjectAnimator
                        .ofFloat(expandedImageView, View.X, startBounds.left))
                        .with(ObjectAnimator
                                .ofFloat(expandedImageView,
                                        View.Y,startBounds.top))
                        .with(ObjectAnimator
                                .ofFloat(expandedImageView,
                                        View.SCALE_X, startScaleFinal))
                        .with(ObjectAnimator
                                .ofFloat(expandedImageView,
                                        View.SCALE_Y, startScaleFinal));
            set.setDuration(mShortAnimationDuration);
            set.setInterpolator(new DecelerateInterpolator());
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }

@Override
                public void onAnimationCancel(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }
            });
            set.start();
            mCurrentAnimator = set;
        }
    });
}

Adding Animations之Zooming a View相关推荐

  1. 0306--iOS之阅读View Controller Programming Guide for iOS---(三)Presentations and Trasitions

    Presenting a View Controller                                                 --显示vc There are two wa ...

  2. Unity3D类人动画humanoid animations

    动画和Mecanim术语表 A Glossary of Animation and Mecanim terms Date:2013-05-24 11:01 Icon 图标 Term 术语 Descri ...

  3. animateWithDuration:animations:completion:

    为什么80%的码农都做不了架构师?>>>    Creates an animation block object that can be used to set up keyfra ...

  4. CREATE VIEW SQL:在SQL Server中使用索引视图

    This is the fourth article in a series of learning the CREATE VIEW SQL statement. So far, we have do ...

  5. Cocoa touch(六):UIViewController

    iOS程序是基于MVC设计模式的,UIViewController是Controller的基类,一般我们通过继承这个类来实现自己的Controller,框架为我们提供了一些定义好的子类,如UINavi ...

  6. 了解如何在20分钟内创建您的第一个Angular应用

    Angular is a JavaScript framework, created my Misko Hevery and maintained by Google. It's an MVC (Mo ...

  7. xcode11 新功能_Xcode 11功能

    xcode11 新功能 WWDC 2019 is over and we can't wait to discuss what's in store for the developers. Today ...

  8. android jni示例_Android动画示例

    android jni示例 Android Animation is used to give the UI a rich look and feel. Animations in android a ...

  9. 关于 Android 平台开发相关的有哪些推荐书籍?

    转自:http://www.zhihu.com/question/19579609 作者:Shan Huang 链接:http://www.zhihu.com/question/19579609/an ...

最新文章

  1. 这个插件竟打通了Python和Excel,还能自动生成代码!
  2. 为什么说特斯拉在自动驾驶上比Waymo更占优势
  3. 【题解】Luogu P2730 魔板
  4. Ubuntu 19.10 发布 | 云原生生态周报 Vol. 24
  5. Java国际化资源绑定-----示例
  6. MySQL的ibdata1文件占用过大
  7. linux实现文本方式与图形方式的转换_Linux下的6款最好用的PDF文档阅览工具
  8. 【AtCoder Grand Contest 036 B】Do Not Duplicate【循环节】
  9. Java在线反编译网站
  10. 使用WebSockets搭建多人在线聊天室
  11. Pdf转Word用Python轻松实现
  12. 关于网站建设的主要流程和步骤(小白指南)
  13. svn conflict linux,解决svn update 产生Node remains in conflict的问题
  14. linux下lamealsa进行音频流操作(四)alsa+lame将音频流转为MP3
  15. ASEMI低压降肖特基二极管怎么检测,低压降肖特基有什么优势
  16. NOPI 读取EXCEL数据时报错“未将对象引用设置到对象的实例”的变相解决方案
  17. Mac M2芯 超详细k8s集群实战 - kubeadm
  18. 数据库关系模型与关系运算---2022.2.13
  19. 如何反编译 cocos creator 生成 的jsc文件/反编译jsc文件(三) , 还原cocos creator 工程
  20. 非常好的免费在线计算机词典

热门文章

  1. 未接响铃1秒是什么意思_空调能耗等级是什么意思 家用有必要买1级空调吗 看了它就明白了...
  2. 鱼塘捕捞周期效益分析
  3. 关于通信方面的总结(通信协议、通信端口)
  4. java-使用 flying-saucer 通过 xhtml 生成 pdf 文档支持 css 和 图片
  5. 服务器安全证书更新失败怎么回事,手机安全证书更新失败怎么办
  6. net-java-php-python-宠物销售系统计算机毕业设计程序
  7. bootstrap地址选择(全国省市选择、定位)功能
  8. 2018传智黑马前端视频教程36期视频与源码完整版
  9. 上海交通大学计算机科学杨岚青博士,上海交通大学2014年硕士生拟录取名单公示(4)...
  10. 深度推荐模型-DIN