You should use setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
because the documentation of the getDimension
method states that it returns a Resource dimension value multiplied by the appropriate metric.
which I understand to be the precalculated absolute px value.
That is, use:
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.text_size_small));