From 689a60dd252e779be0c47cc8d37fd54bbd67bc2e Mon Sep 17 00:00:00 2001 From: Scott Main Date: Wed, 21 Sep 2011 17:56:47 -0700 Subject: [PATCH] fix custom view sample to scale text based on screen density Change-Id: I2e08e90b7baa73a4e36bad9f6abb9364d7b471d1 --- .../ApiDemos/src/com/example/android/apis/view/LabelView.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/ApiDemos/src/com/example/android/apis/view/LabelView.java b/samples/ApiDemos/src/com/example/android/apis/view/LabelView.java index b98a5b573..b0a1f963b 100644 --- a/samples/ApiDemos/src/com/example/android/apis/view/LabelView.java +++ b/samples/ApiDemos/src/com/example/android/apis/view/LabelView.java @@ -84,7 +84,8 @@ public class LabelView extends View { private final void initLabelView() { mTextPaint = new Paint(); mTextPaint.setAntiAlias(true); - mTextPaint.setTextSize(16); + // Must manually scale the desired text size to match screen density + mTextPaint.setTextSize(16 * getResources().getDisplayMetrics().density); mTextPaint.setColor(0xFF000000); setPadding(3, 3, 3, 3); } @@ -104,6 +105,7 @@ public class LabelView extends View { * @param size Font size */ public void setTextSize(int size) { + // This text size has been pre-scaled by the getDimensionPixelOffset method mTextPaint.setTextSize(size); requestLayout(); invalidate();