Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
public class TemplateCustomView extends View {
private long mLastInvalidate;
private boolean mIsOnDetachedFromWindow;
public TemplateCustomView(Context context) {
this(context, null, 0);
}
public TemplateCustomView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public TemplateCustomView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView();
}
private void initView() {
}
@Override
protected void onAttachedToWindow() {
mIsOnDetachedFromWindow = false;
super.onAttachedToWindow();
}
@Override
protected void onDetachedFromWindow() {
//AnimatorのCancel処理
mIsOnDetachedFromWindow = true;
super.onDetachedFromWindow();
}
@Override
public void invalidate() {
if (SystemClock.uptimeMillis() - mLastInvalidate < 30 || mIsOnDetachedFromWindow) {
return;
}
mLastInvalidate = SystemClock.uptimeMillis();
super.invalidate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment