Skip to content

Commit

Permalink
Fix the bug that the floating label scrolls up with the text.
Browse files Browse the repository at this point in the history
  • Loading branch information
rengwuxian committed Apr 28, 2015
1 parent 99a0c87 commit fed912b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1371,16 +1371,15 @@ protected void onDraw(@NonNull Canvas canvas) {
}

// calculate the vertical position
int floatingLabelStartY = innerPaddingTop + floatingLabelTextSize + floatingLabelPadding;
int distance = floatingLabelPadding;
int position = (int) (floatingLabelStartY - distance * (floatingLabelAlwaysShown ? 1 : floatingLabelFraction));
int floatingLabelStartY = (int) (innerPaddingTop + floatingLabelTextSize + floatingLabelPadding - distance * (floatingLabelAlwaysShown ? 1 : floatingLabelFraction) + getScrollY());

// calculate the alpha
int alpha = ((int) ((floatingLabelAlwaysShown ? 1 : floatingLabelFraction) * 0xff * (0.74f * focusFraction + 0.26f) * (floatingLabelTextColor != -1 ? 1 : Color.alpha(floatingLabelTextColor) / 256f)));
textPaint.setAlpha(alpha);

// draw the floating label
canvas.drawText(floatingLabelText.toString(), floatingLabelStartX, position, textPaint);
canvas.drawText(floatingLabelText.toString(), floatingLabelStartX, floatingLabelStartY, textPaint);
}

// draw the bottom ellipsis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1371,16 +1371,15 @@ protected void onDraw(@NonNull Canvas canvas) {
}

// calculate the vertical position
int floatingLabelStartY = innerPaddingTop + floatingLabelTextSize + floatingLabelPadding;
int distance = floatingLabelPadding;
int position = (int) (floatingLabelStartY - distance * (floatingLabelAlwaysShown ? 1 : floatingLabelFraction));
int floatingLabelStartY = (int) (innerPaddingTop + floatingLabelTextSize + floatingLabelPadding - distance * (floatingLabelAlwaysShown ? 1 : floatingLabelFraction) + getScrollY());

// calculate the alpha
int alpha = ((int) ((floatingLabelAlwaysShown ? 1 : floatingLabelFraction) * 0xff * (0.74f * focusFraction + 0.26f) * (floatingLabelTextColor != -1 ? 1 : Color.alpha(floatingLabelTextColor) / 256f)));
textPaint.setAlpha(alpha);

// draw the floating label
canvas.drawText(floatingLabelText.toString(), floatingLabelStartX, position, textPaint);
canvas.drawText(floatingLabelText.toString(), floatingLabelStartX, floatingLabelStartY, textPaint);
}

// draw the bottom ellipsis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1368,16 +1368,15 @@ protected void onDraw(@NonNull Canvas canvas) {
}

// calculate the vertical position
int floatingLabelStartY = innerPaddingTop + floatingLabelTextSize + floatingLabelPadding;
int distance = floatingLabelPadding;
int position = (int) (floatingLabelStartY - distance * (floatingLabelAlwaysShown ? 1 : floatingLabelFraction));
int floatingLabelStartY = (int) (innerPaddingTop + floatingLabelTextSize + floatingLabelPadding - distance * (floatingLabelAlwaysShown ? 1 : floatingLabelFraction) + getScrollY());

// calculate the alpha
int alpha = ((int) ((floatingLabelAlwaysShown ? 1 : floatingLabelFraction) * 0xff * (0.74f * focusFraction + 0.26f) * (floatingLabelTextColor != -1 ? 1 : Color.alpha(floatingLabelTextColor) / 256f)));
textPaint.setAlpha(alpha);

// draw the floating label
canvas.drawText(floatingLabelText.toString(), floatingLabelStartX, position, textPaint);
canvas.drawText(floatingLabelText.toString(), floatingLabelStartX, floatingLabelStartY, textPaint);
}

// draw the bottom ellipsis
Expand Down

0 comments on commit fed912b

Please sign in to comment.