summaryrefslogtreecommitdiff
path: root/samples/ApiDemos/src/com/example/android/apis/view/LabelView.java
diff options
context:
space:
mode:
authorScott Main <smain@google.com>2011-09-21 17:56:47 -0700
committerScott Main <smain@google.com>2011-09-21 17:57:59 -0700
commit689a60dd252e779be0c47cc8d37fd54bbd67bc2e (patch)
tree23b0a1d0da2afc37ee0ec7d178b42d849a152853 /samples/ApiDemos/src/com/example/android/apis/view/LabelView.java
parent318ae8e9feddb5665a137c1b6f9c911cf50aeea0 (diff)
fix custom view sample to scale text based on screen density
Change-Id: I2e08e90b7baa73a4e36bad9f6abb9364d7b471d1
Diffstat (limited to 'samples/ApiDemos/src/com/example/android/apis/view/LabelView.java')
-rw-r--r--samples/ApiDemos/src/com/example/android/apis/view/LabelView.java4
1 files changed, 3 insertions, 1 deletions
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();