1、获取Layout布局
LinearLayout mParent=(LinearLayout)findViewById(R.id.UnityView);
2、获取Unity视图
View mView=mUnityPlayer.getView();
3、将Unity视图添加到Android视图中
mParent.addView(mView);
4、获取LayoutParams
??????? LinearLayout会报错,根据报错内容,定义了ConstraintLayout。
ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams)mParent.getLayoutParams();
5、创建一个ValueAnimator
ValueAnimator valueAnimator = ValueAnimator.ofInt(10,300);
6、添加监听
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
layoutParams.setMarginEnd((int)valueAnimator.getAnimatedValue());
mParent.setLayoutParams(layoutParams);
}
});
7、设置时间,并启动动画
valueAnimator.setDuration(3000);
valueAnimator.start();
|