views:

154

answers:

1

Calling TextView.setTextSize is working abnormally. Right after the call to setTextSize if we get a getTextSize its returning a much higher value that what we set it to earlier.

Here's what we're doing:

        zoomControl.setOnZoomInClickListener(new OnClickListener() {
            public void onClick(View view) {
                float size = mViewShabad.getTextSize() + 1;
                textView.setTextSize(size);
            }
        });

Has anyone seen this before?

+1  A: 

The difference here is that in the setTextSize(int size) method, the unit type by default is "sp" or "scaled pixels". This value will be a different pixel dimension for each screen density (ldpi, mdpi, hdpi).

getTextSize(), on the other hand, returns the actual pixel dimensions of the text.

You can use setTextSize(int unit, int size) to specify a unit type. The values for this can be found in the TypedValues class, but some of them are:

TypedValues.COMPLEX_UNIT_PX : Pixels

TypedValues.COMPLEX_UNIT_SP : Scaled Pixels

TypedValues.COMPLEX_UNIT_DIP : Device Independent Pixels

kcoppock
I just found that and was about to post it here. Thanks a lot!
singhspk
No problem! :) It was good for me to learn too, haha. Strange there's no way to return different values, but I'm sure it's an easy conversion if I looked into it.
kcoppock