0

I have a dimension resource value as

<dimen name="arrowButton_textValue_textSize">20sp</dimen>

I use that value in two following ways

<TextView
android:id="@+id/arrowButton_textValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/arrowButton_textValue_textSize"/>

and

float _textSize = getResources().getDimension(R.dimen.arrowButton_textValue_textSize);
TextView _textView = (TextView) findViewById(R.id.arrowButton_textValue);
_textView.setTextSize(_textSize);

I thought those two methods are identical though they cause different text size on real devices. For instance on some devices (HTC Wildfire S) they look the same but on HTC Desire they aren't and the second method generates bigger text size

How may I convert a dimension to exact floating point on real device based on device actual display metrics?

anonim
  • 2,494
  • 6
  • 30
  • 40

0 Answers0