0
我在android中使用一些动画创建了简单的应用程序。在我的布局中,我有一个带有一个sourceImage和一个按钮的ImageView。当我点击按钮时,我希望它在同一时间移动并调整大小。 我使用ObjectAnimator和ValueAnimator创建动画,并与animatorSet一起播放它们。我的问题是,我的按钮不能顺利移动。 我查了几个动画库,如Transitions Everywhere和APIDemos。在这些库中,当我设置ImageBackground时,视图无法平稳移动 并且它们都有我的问题。 任何人都可以帮我解决这个问题吗?Android动画在BackgroundImage上不流畅
我的布局代码:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageview"
android:fitsSystemWindows="true"
android:src="@drawable/image"
android:scaleType="fitXY" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frame">
<Button
android:layout_width="100dp"
android:layout_height="45dp"
android:id="@+id/btn_start"
android:layout_gravity="center_horizontal|bottom"
android:gravity="center_vertical|center_horizontal"
android:textAllCaps="false"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Start" />
// ....................
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
我的动画代码:
btn_start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ButtonAnimation();
}
});
private void ButtonAnimation() {
Animator moveButtonAnimY = ObjectAnimator.ofFloat(btn_start, "translationY", 0, 200)
.setDuration(500);
final ValueAnimator valueAnimator = ValueAnimator.ofFloat(width_btn_start, width_btn_start * 2.0f);
valueAnimator.setDuration(500);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Integer value = (Integer) animation.getAnimatedValue();
btn_start.getLayoutParams().width = value.intValue();
btn_start.requestLayout();
}
});
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(moveButtonAnimY, valueAnimator);
animatorSet.start();
}
阿洛克,我测试你的代码在我的LG G3,但不会看到动画速度的任何变化! – MohsenTi