List of usage examples for android.text Layout getLineTop
public abstract int getLineTop(int line);
From source file:com.amazon.android.ui.widget.ReadTextView.java
/** * Which line in the layout is the top visible line. * * @param layout Calculated text layout. * @param bounds Visible bounds in the coordinates of the TextView and layout. * @return The top visible line./*from w ww .j a v a 2 s. c o m*/ */ private int topVisibleLineOfText(final Layout layout, final Rect bounds) { final int lineCount = layout.getLineCount(); for (int lineNum = 0; lineNum < lineCount; lineNum++) { final int top = layout.getLineTop(lineNum); if (top >= bounds.top && top <= bounds.bottom) { return lineNum; } } return lineCount; }
From source file:com.amazon.android.ui.widget.ReadTextView.java
/** * Draw a gradient on the text so that the bottom and top line have a faded effect if the user * can scroll in that direction.//from w w w . ja v a2s.c o m */ private void updateGradient() { if (mText == null || mScrollView == null) { return; } final Layout layout = mText.getLayout(); assert layout != null; final Rect bounds = new Rect(); getTextBounds(bounds); final int topLine = topVisibleLineOfText(layout, bounds); final int bottomLine = bottomVisibleLineOfText(layout, bounds); final int fullHeight = layout.getHeight(); if (fullHeight > 0) { final float bottomLineHeight = layout.getLineBottom(bottomLine) - layout.getLineTop(bottomLine); final float topLineHeight = layout.getLineBottom(topLine) - layout.getLineTop(topLine); this.setFadingEdgeLength((int) Math.max(topLineHeight, bottomLineHeight)); } }