i create a custom layout for auto - animation when it visible or gone. Here my code:
public class DidiRelativeLayout extends RelativeLayout {
private AnimUtils animUtils;
private int animVisible, animGone, durVisible, durGone;
public DidiRelativeLayout(Context context) {
super(context);
animUtils = AnimUtils.getInstance(context);
}
public DidiRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
animUtils = AnimUtils.getInstance(context);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.DidiRelativeLayout, 0, 0);
try {
animVisible = ta.getInteger(R.styleable.DidiRelativeLayout_anim_visible, -1);
animGone = ta.getInteger(R.styleable.DidiRelativeLayout_anim_gone, -1);
durVisible = ta.getInteger(R.styleable.DidiRelativeLayout_anim_visible_duration, AttributeConst.DEFAULT_DURATION_ANIMATION);
durGone = ta.getInteger(R.styleable.DidiRelativeLayout_anim_gone_duration, AttributeConst.DEFAULT_DURATION_ANIMATION);
} finally {
ta.recycle();
}
}
public DidiRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
animUtils = AnimUtils.getInstance(context);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.DidiRelativeLayout, defStyleAttr, 0);
try {
animVisible = ta.getInteger(R.styleable.DidiRelativeLayout_anim_visible, -1);
animGone = ta.getInteger(R.styleable.DidiRelativeLayout_anim_gone, -1);
durVisible = ta.getInteger(R.styleable.DidiRelativeLayout_anim_visible_duration, AttributeConst.DEFAULT_DURATION_ANIMATION);
durGone = ta.getInteger(R.styleable.DidiRelativeLayout_anim_gone_duration, AttributeConst.DEFAULT_DURATION_ANIMATION);
} finally {
ta.recycle();
}
}
@Override
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);
try {
switch (visibility) {
case VISIBLE:
startAnimation(getAnim(animVisible, durVisible));
break;
case INVISIBLE:
case GONE:
startAnimation(getAnim(animGone, durGone));
break;
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
It work fine, but when activity resume from some where, onVisibilityChanged auto-call. How can i avoid it? Thanks.
Update: full code of custom layout