对不起,我英语不好。很长一段时间以来,我一直在面对这个问题,但仍然无法解决。当我使用系统自己的ChangeBounds时没有问题。但是当我把Main2Acivity放在transition和SetDuration(3000)中时;删除动画后,没有任务问题。
我的代码如下:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(this,findViewById(R.id.iv),"iv");
startActivity(new Intent(this, Main2Activity.class), activityOptionsCompat.toBundle());
}
}
}
public class Main2Activity extends AppCompatActivity {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
MyTransition transition = new MyTransition();
transition.addTarget("iv");
transition.setDuration(3000);
getWindow().setSharedElementEnterTransition(transition);
}
}
public class MyTransition extends Transition {
@Override
public void captureStartValues(TransitionValues transitionValues) {
Log.e("FMY", "captureStartValues:" + transitionValues.view.hashCode());
transitionValues.values.put("x", transitionValues.view.getX());
transitionValues.values.put("y", transitionValues.view.getY());
}
@Override
public void captureEndValues(TransitionValues transitionValues) {
Log.e("FMY", "captureEndValues:" + transitionValues.view.hashCode());
transitionValues.values.put("x", transitionValues.view.getX());
transitionValues.values.put("y", transitionValues.view.getY());
}
@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
Log.e("FMY", "createAnimator");
// endValues.view.setTranslationX();
PropertyValuesHolder propertyValuesHolderX = PropertyValuesHolder.ofFloat("x", ((Float) startValues.values.get("x")), ((Float) endValues.values.get("x")));
PropertyValuesHolder propertyValuesHolderY = PropertyValuesHolder.ofFloat("y", ((Float) startValues.values.get("y")), ((Float) endValues.values.get("y")));
ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(endValues.view, propertyValuesHolderX,propertyValuesHolderY);
objectAnimator.setDuration(3000);
return objectAnimator;
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:background="#fff"
android:id="@+id/rott"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/iv"
android:onClick="onClick"
android:layout_width="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"/>
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:background="#f0f"
android:layout_height="match_parent"
tools:context=".Main2Activity">
<ImageView
android:transitionName="iv"
android:id="@+id/iv"
android:layout_width="109dp"
android:src="@mipmap/ic_launcher"
android:layout_height="230dp"/>
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:0)
动画以其视图移动dockerView作为父布局执行