如何设置Padding以使用动画查看?

时间:2017-09-02 11:29:17

标签: android android-animation

我尝试ValueAnimator,但我无法为其设置多个属性。

ValueAnimator animate = ValueAnimator.ofInt(leftO, left, topO, top, rightO, right, bottomO, bottom);
    animate.setDuration(250);
    animate.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            greenTarget.setPadding(valueAnimator.getAnimatedValue(), ? ? ?);
        }
    });
    animate.start();

那么,该怎么做?也许使用ObjectAnimator代替?如果是这样,如何设置Padding?

2 个答案:

答案 0 :(得分:1)

ValueAnimator animator = ValueAnimator.ofInt(view.getPaddingRight(), _20dp);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() 
 {
    @Override
    public void onAnimationUpdate(ValueAnimator valueAnimator){
    view.setPadding(_6dp, _6dp, (Integer) 
    valueAnimator.getAnimatedValue(), 0);
  }
});
animator.setDuration(200);
animator.start();

答案 1 :(得分:0)

您可以尝试使用允许在起始属性值(例如xml中定义的值)和更改值(例如以编程方式定义)之间动画的TransitionManager

你需要你的xml的根布局,我在这里命名为mViewGroup,以及要动画的视图的直接父级的布局类型,例如LinearLayout:

{
  "errorMessage": "Cannot find module '/var/task/index'",
  "errorType": "Error",
  "stackTrace": [
    "Module.require (module.js:497:17)",
    "require (internal/module.js:20:19)"
  ]
}

START RequestId: 9e17d7d0-8fd8-11e7-a461-4f1c735f787e Version: $LATEST
Unable to import module 'index': Error
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
END RequestId: 9e17d7d0-8fd8-11e7-a461-4f1c735f787e
REPORT RequestId: 9e17d7d0-8fd8-11e7-a461-4f1c735f787e  Duration: 1.83 ms   Billed Duration: 100 ms     Memory Size: 1536 MB    Max Memory Used: 20 MB  

希望这有帮助。