Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance Issue #3

zyallday opened this issue Dec 20, 2017 · 0 comments


Copy link

commented Dec 20, 2017

  1. Avoid creating objects while calling onDraw. You can create new Paint(); in constructor.
  2. The code below:
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
	super.onLayout(changed, left, top, right, bottom);

	List<Float> floatList = getGraduateFloatList(stepNum, viewHeight);
	generateAnim(floatList, barNum);

When the indicator inflates in a ListView/RecyclerView , onLayout will be called many times.Then there will be many animator objects being created. It will cause performance issue. You could do like this:

public Indicator(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
       getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override public boolean onPreDraw() {
                    if (0 != viewWidth && 0 != viewHeight) {
                          List<Float> floatList = getGraduateFloatList(stepNum, viewHeight);
                          generateAnim(floatList, barNum);
               return false;


Forgive my poor english.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.