Fix autoscroll position calculation in the MoveListView

When computing the autoscroll Y position the parts of characters
descending below the font baseline were visible for the line before
the first line that was supposed to be visible.

Also add a small margin above the move list to separate it somewhat
from the button row.
This commit is contained in:
Peter Osterlund 2020-01-12 01:13:37 +01:00
parent 1afda36d85
commit 9fbf7ff212
3 changed files with 15 additions and 2 deletions

View File

@ -1995,7 +1995,7 @@ public class DroidFish extends Activity
int currPos = gameTextListener.getCurrPos();
int line = moveList.getLineForOffset(currPos);
if (line >= 0 && autoScrollMoveList) {
int y = (line - 1) * moveList.getLineHeight();
int y = moveList.getLineStartY(line - 1);
moveListScroll.scrollTo(0, y);
}
}

View File

@ -103,6 +103,18 @@ public class MoveListView extends View {
return textPaint.getFontMetricsInt(null);
}
/** Get the Y scroll value required to put line "lineNo" at the top of the view. */
public int getLineStartY(int lineNo) {
if (lineNo < 0)
return 0;
Paint.FontMetricsInt fmi = new Paint.FontMetricsInt();
int lineHeight = textPaint.getFontMetricsInt(fmi);
int y = lineHeight * lineNo;
if (lineNo > 0 && fmi.bottom > 0)
y += fmi.bottom - 1;
return y;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

View File

@ -91,7 +91,8 @@
<ScrollView
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_height="fill_parent"
android:layout_marginTop="4dp">
<view
class="org.petero.droidfish.view.MoveListView"