2

可能重复:
动画 ImageView 宽度而不缩放

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

我尝试更改 scaleType,然后将 ScaleAnimation 直接应用于该 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"
    />

爪哇:

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:

布局:

<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>

爪哇:

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 仍在缩放。我希望有人能指出我正确的方向。

4

1 回答 1

9

尝试将动画翻译为

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

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

于 2012-10-22T13:20:50.757 回答