Do not draw the fade areas when it's not necessary.

Prior to this change, every singleLine TextView would create, draw
and compose a layer on every draw dispatch. This was unnecessary and
expensive.

Change-Id: Ia4f79d7fc8f485784fe6b795f0f196d38d579838
This commit is contained in:
Romain Guy
2010-07-08 11:40:54 -07:00
parent 132f22590a
commit dac5f9f3ca
2 changed files with 8 additions and 6 deletions

View File

@@ -6848,16 +6848,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
if (verticalEdges) {
topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength()));
drawTop = topFadeStrength >= 0.0f;
drawTop = topFadeStrength > 0.0f;
bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength()));
drawBottom = bottomFadeStrength >= 0.0f;
drawBottom = bottomFadeStrength > 0.0f;
}
if (horizontalEdges) {
leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength()));
drawLeft = leftFadeStrength >= 0.0f;
drawLeft = leftFadeStrength > 0.0f;
rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength()));
drawRight = rightFadeStrength >= 0.0f;
drawRight = rightFadeStrength > 0.0f;
}
saveCount = canvas.getSaveCount();

View File

@@ -6790,8 +6790,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
@Override
protected int computeHorizontalScrollRange() {
if (mLayout != null)
return mLayout.getWidth();
if (mLayout != null) {
return mSingleLine && (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.LEFT ?
(int) mLayout.getLineWidth(0) : mLayout.getWidth();
}
return super.computeHorizontalScrollRange();
}