图像缩放动画相对于中心点的Andr​​oid [英] Android image scale animation relative to center point

查看:195
本文介绍了图像缩放动画相对于中心点的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ImageView的,我做了一个简单的规模的动画吧。很标准的code。

I have an ImageView and I do a simple scale animation to it. Very standard code.

我的scale_up.xml:

My scale_up.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale android:fromXScale="1"
           android:fromYScale="1"
           android:toXScale="1.2"
           android:toYScale="1.2"
           android:duration="175"/>
</set>

我的动漫code:

My animation code:

Animation a = AnimationUtils.loadAnimation(this, R.anim.scale_up);
((ImageView) findViewById(R.id.circle_image)).startAnimation(a);

问题:

当该图像缩放它不从中心比例的,而是从左上角。换句话说,图像的经缩放版本构建不具有相同的点为中心,但它具有相同的左上角点。 下面是解释我的意思的链接。的第一个图像是如何动画秤,和第二图像是我想要的规模。它应该保持的中心点相同。我试图建立重力的图像上,在容器上,对准左或右时,它总是缩放相同。 我使用RelativeLayout的主画面和ImageView的酒店到另一个RelativeLayout的,但我想其他的布局,没有任何变化。

When the image scales it doesn't scale from the center, but from the top left corner. In other word, the scaled verion of the image doesn't have the same point as center, but it has the same top-left point. Here's a link that explains what I mean. The first image is how the animation scales, and the second image is how I want it to scale. It should keep the center point the same. I have tried setting up gravity on the image, on the container, aligning left or right, it always scales the same. I'm using RelativeLayout for the main screen and ImageView is located into another RelativeLayout, but I tried other layouts, no change.

推荐答案

忘了额外的转换,设置安卓pivotX 安卓pivotY 来一半的宽度和高度,这将扩展从图像的中心

Forget the additional translation, set android:pivotX, android:pivotY to half the width and height and it will scale from the center of the image.

这篇关于图像缩放动画相对于中心点的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆