mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2024-11-23 11:31:33 +01:00
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:
parent
1afda36d85
commit
9fbf7ff212
|
@ -1995,7 +1995,7 @@ public class DroidFish extends Activity
|
||||||
int currPos = gameTextListener.getCurrPos();
|
int currPos = gameTextListener.getCurrPos();
|
||||||
int line = moveList.getLineForOffset(currPos);
|
int line = moveList.getLineForOffset(currPos);
|
||||||
if (line >= 0 && autoScrollMoveList) {
|
if (line >= 0 && autoScrollMoveList) {
|
||||||
int y = (line - 1) * moveList.getLineHeight();
|
int y = moveList.getLineStartY(line - 1);
|
||||||
moveListScroll.scrollTo(0, y);
|
moveListScroll.scrollTo(0, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,18 @@ public class MoveListView extends View {
|
||||||
return textPaint.getFontMetricsInt(null);
|
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
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
|
|
@ -91,7 +91,8 @@
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:id="@+id/scrollView"
|
android:id="@+id/scrollView"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent">
|
android:layout_height="fill_parent"
|
||||||
|
android:layout_marginTop="4dp">
|
||||||
|
|
||||||
<view
|
<view
|
||||||
class="org.petero.droidfish.view.MoveListView"
|
class="org.petero.droidfish.view.MoveListView"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user