可能重复:
无缩放动画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"
/>
Run Code Online (Sandbox Code Playgroud)
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);
Run Code Online (Sandbox Code Playgroud)
我还尝试将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>
Run Code Online (Sandbox Code Playgroud)
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);
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,ImageView仍在缩放.我希望有人能指出我正确的方向.
尝试将动画翻译为
Animation animation1=new TranslateAnimation(0.0f, 200.0f, 0.0f, 0.0f);
animation1.setDuration(5000);
imageview.startAnimation(animation1);
Run Code Online (Sandbox Code Playgroud)
你可以TranslateAnimation(fromX, toX, fromY, toY)像我在上面的代码中那样设置你的坐标
| 归档时间: |
|
| 查看次数: |
7402 次 |
| 最近记录: |