我需要ImageView使用平滑的动画从屏幕的左侧到右侧制作幻灯片(我想ImageView在转换过程中看到它)我尝试使用以下代码:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
camion.animate()
.translationX(width)
.setDuration(2000)
.setInterpolator(new LinearInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
//camion.setVisibility(View.GONE);
}
});
Run Code Online (Sandbox Code Playgroud)
在ImageView移动,但在动画laggy,而不是光滑如我想.我在代码上做错了什么?
可能重复:
无缩放动画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仍在缩放.我希望有人能指出我正确的方向.