从左到右显示ImageView的动画 [英] Animation to show ImageView from left to right

查看:98
本文介绍了从左到右显示ImageView的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
对ImageView宽度进行动画处理而不进行缩放

我想做的是创建一个动画,其中从左到右显示一个ImageView(剪辑动画?).图片不应该缩放.

What I'm trying to do is to create an animation where an ImageView is shown starting from the left to the right (clipping animation?). The image should not be scaled.

我尝试更改scaleType,然后将ScaleAnimation直接应用于该ImageView:

I tried changing the scaleType and then applying a ScaleAnimation directly to that ImageView:

布局:

<ImageView
    android:id="@+id/graphImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:scaleType="centerCrop"
    android:background="@android:color/transparent"
    android:contentDescription="@string/stroom_grafiek"
    />

Java:

scale = new ScaleAnimation((float)0,
        (float)1, (float)1, (float)1,
        Animation.RELATIVE_TO_SELF, (float)0,
        Animation.RELATIVE_TO_SELF, (float)1);
scale.setDuration(1000);

graphImage.startAnimation(scale);

我还尝试将ImageView放在RelativeLayout内,然后将动画应用于RelativeLayout:

I also tried to put the ImageView inside a RelativeLayout, and then apply the animation to the RelativeLayout:

布局:

<RelativeLayout 
    android:id="@+id/graphImageInnerWrap"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/transparent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:clipChildren="true"
    >
    <ImageView
        android:id="@+id/graphImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="matrix"
        android:background="@android:color/transparent"
        android:contentDescription="@string/stroom_grafiek"
        />
</RelativeLayout>

Java:

scale = new ScaleAnimation((float)0,
        (float)1, (float)1, (float)1,
        Animation.RELATIVE_TO_SELF, (float)0,
        Animation.RELATIVE_TO_SELF, (float)1);
scale.setDuration(1000);

graphImageInnerWrap.startAnimation(scale);

在两种情况下,ImageView仍在缩放.我希望有人能指出我正确的方向.

In both cases the ImageView is still being scaled. I hope someone can point me in the right direction.

推荐答案

尝试将动画翻译为

Animation animation1=new TranslateAnimation(0.0f, 200.0f, 0.0f, 0.0f);
animation1.setDuration(5000);
imageview.startAnimation(animation1);

就像我在上面的代码中所做的那样,您可以在 TranslateAnimation(fromX,toX,fromY,toY)中设置坐标

and you can set your coordinates in TranslateAnimation(fromX, toX, fromY, toY) as I have done in above code

这篇关于从左到右显示ImageView的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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