Methods Summary |
---|
public void | draw(android.graphics.Canvas canvas)
final boolean vertical = mVertical;
final int extent = mExtent;
final int range = mRange;
boolean drawTrack = true;
boolean drawThumb = true;
if (extent <= 0 || range <= extent) {
drawTrack = vertical ? mAlwaysDrawVerticalTrack : mAlwaysDrawHorizontalTrack;
drawThumb = false;
}
Rect r = getBounds();
if (canvas.quickReject(r.left, r.top, r.right, r.bottom,
Canvas.EdgeType.AA)) {
return;
}
if (drawTrack) {
drawTrack(canvas, r, vertical);
}
if (drawThumb) {
int size = vertical ? r.height() : r.width();
int thickness = vertical ? r.width() : r.height();
int length = Math.round((float) size * extent / range);
int offset = Math.round((float) (size - length) * mOffset / (range - extent));
// avoid the tiny thumb
int minLength = thickness * 2;
if (length < minLength) {
length = minLength;
}
// avoid the too-big thumb
if (offset + length > size) {
offset = size - length;
}
drawThumb(canvas, r, offset, length, vertical);
}
|
protected void | drawThumb(android.graphics.Canvas canvas, android.graphics.Rect bounds, int offset, int length, boolean vertical)
final Rect thumbRect = mTempBounds;
final boolean changed = mRangeChanged || mChanged;
if (changed) {
if (vertical) {
thumbRect.set(bounds.left, bounds.top + offset,
bounds.right, bounds.top + offset + length);
} else {
thumbRect.set(bounds.left + offset, bounds.top,
bounds.left + offset + length, bounds.bottom);
}
}
if (vertical) {
final Drawable thumb = mVerticalThumb;
if (changed) thumb.setBounds(thumbRect);
thumb.draw(canvas);
} else {
final Drawable thumb = mHorizontalThumb;
if (changed) thumb.setBounds(thumbRect);
thumb.draw(canvas);
}
|
protected void | drawTrack(android.graphics.Canvas canvas, android.graphics.Rect bounds, boolean vertical)
Drawable track;
if (vertical) {
track = mVerticalTrack;
} else {
track = mHorizontalTrack;
}
if (track != null) {
if (mChanged) {
track.setBounds(bounds);
}
track.draw(canvas);
}
|
public boolean | getAlwaysDrawHorizontalTrack()Indicates whether the horizontal scrollbar track should always be drawn regardless of the
extent.
return mAlwaysDrawHorizontalTrack;
|
public boolean | getAlwaysDrawVerticalTrack()Indicates whether the vertical scrollbar track should always be drawn regardless of the
extent.
return mAlwaysDrawVerticalTrack;
|
public int | getOpacity()
return PixelFormat.TRANSLUCENT;
|
public int | getSize(boolean vertical)
if (vertical) {
return (mVerticalTrack != null ?
mVerticalTrack : mVerticalThumb).getIntrinsicWidth();
} else {
return (mHorizontalTrack != null ?
mHorizontalTrack : mHorizontalThumb).getIntrinsicHeight();
}
|
protected void | onBoundsChange(android.graphics.Rect bounds)
super.onBoundsChange(bounds);
mChanged = true;
|
public void | setAlpha(int alpha)
if (mVerticalTrack != null) {
mVerticalTrack.setAlpha(alpha);
}
mVerticalThumb.setAlpha(alpha);
if (mHorizontalTrack != null) {
mHorizontalTrack.setAlpha(alpha);
}
mHorizontalThumb.setAlpha(alpha);
|
public void | setAlwaysDrawHorizontalTrack(boolean alwaysDrawTrack)Indicate whether the horizontal scrollbar track should always be drawn regardless of the
extent. Defaults to false.
mAlwaysDrawHorizontalTrack = alwaysDrawTrack;
|
public void | setAlwaysDrawVerticalTrack(boolean alwaysDrawTrack)Indicate whether the vertical scrollbar track should always be drawn regardless of the
extent. Defaults to false.
mAlwaysDrawVerticalTrack = alwaysDrawTrack;
|
public void | setColorFilter(android.graphics.ColorFilter cf)
if (mVerticalTrack != null) {
mVerticalTrack.setColorFilter(cf);
}
mVerticalThumb.setColorFilter(cf);
if (mHorizontalTrack != null) {
mHorizontalTrack.setColorFilter(cf);
}
mHorizontalThumb.setColorFilter(cf);
|
public void | setHorizontalThumbDrawable(android.graphics.drawable.Drawable thumb)
if (thumb != null) {
mHorizontalThumb = thumb;
}
|
public void | setHorizontalTrackDrawable(android.graphics.drawable.Drawable track)
mHorizontalTrack = track;
|
public void | setParameters(int range, int offset, int extent, boolean vertical)
if (mVertical != vertical) {
mChanged = true;
}
if (mRange != range || mOffset != offset || mExtent != extent) {
mRangeChanged = true;
}
mRange = range;
mOffset = offset;
mExtent = extent;
mVertical = vertical;
|
public void | setVerticalThumbDrawable(android.graphics.drawable.Drawable thumb)
if (thumb != null) {
mVerticalThumb = thumb;
}
|
public void | setVerticalTrackDrawable(android.graphics.drawable.Drawable track)
mVerticalTrack = track;
|
public java.lang.String | toString()
return "ScrollBarDrawable: range=" + mRange + " offset=" + mOffset +
" extent=" + mExtent + (mVertical ? " V" : " H");
|