When you define a dimension in a resource file you include themeasurement unit. If you use sp units they are scaled according tothe screen density so text at 15sp should appear roughly the samesize on screens of differing density. (The real screen density ofthe device isn't going to exactly match as Android generalisesscreen density into 120, 160, 240 and 320 dpi groups.)
When calling getResources().getDimension(R.dimen.textsize) it willreturn the size in pixels. If using sp it will scaled by the screendensity,
Calling setText(float) sets the size in sp units. This is where theissue is ie you have pixels measurements on one hand and sp unit onthe other to fix do this:
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
getResources().getDimension(R.dimen.textsize));
Note you can also use
getResources().getDimensionPixelSize(R.dimen.textSize);
instead of getDimension() and it will round and convert to an nonfractional value.