-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimateWidth.java
More file actions
44 lines (35 loc) · 1.26 KB
/
Copy pathAnimateWidth.java
File metadata and controls
44 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.{package};
import android.animation.ValueAnimator;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
public class AnimateWidth {
private View parentView;
private int layoutId;
private int animationTime;
private int baseWidth;
private int widthToReach;
private View layoutToAnim;
public AnimateWidth(View view, int id, int time, int widthFrom, int widthTo) {
parentView = view;
layoutId = id;
animationTime = time;
baseWidth = widthFrom;
widthToReach = widthTo;
}
public void playAnimation() {
layoutToAnim = parentView.findViewById(layoutId);
ValueAnimator anim = ValueAnimator.ofInt(baseWidth, widthToReach);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int val = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = layoutToAnim.getLayoutParams();
layoutParams.width = val;
layoutToAnim.setLayoutParams(layoutParams);
}
});
anim.setDuration(animationTime);
anim.start();
}
}