0

I am fixing up an application that someone before me had created and was noticing some strange behavior. Some of the text size, on my main menu particularly, is not changing when I change my font size in my system settings. Here is the code for setting up the text size in my activity. The value in question is landing_text_size

        int height = (int) displayHeight;
    int width = (int) displayWidth;
    textSize = getApplicationContext().getResources().getDimension(
            R.dimen.landing_text_size);
    textViewHeight = (int) ((textSize * 2) + 40);
    // int separatorHeight = (int) getApplicationContext().getResources()
    // .getDimension(R.dimen.landing_grid_margin);
    int space = (int) ((getApplicationContext().getResources()
            .getDimension(R.dimen.landing_grid_view_space)));
    columnWidth = (int) ((height
            - ((int) (getApplicationContext().getResources()
                    .getDimension(R.dimen.landing_header_size)))
            - ((int) (getApplicationContext().getResources()
                    .getDimension(R.dimen.landing_footer_size)))
            - (textViewHeight * numberOfRows) - (space * numberOfRows)) / numberOfRows);

    gridView = (GridView) findViewById(R.id.gridViewLandingPage);
    gridView.setColumnWidth(columnWidth);
    initializeGridView();

    gridView = (GridView) findViewById(R.id.gridViewLandingPage);
    gridView.setColumnWidth(columnWidth);

And later on the code where it sets the text size for the text view.

textView.setTextSize(textSize);

I have been looking into different ways to establish text-size in your xml files and found this question: What is the difference between "px", "dp", "dip" and "sp" on Android?

The obvious idea would be to use sp when declaring my text-size in my dimensions file. The thing is, I am.

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <dimen name="landing_image_size">70dp</dimen>
    <dimen name="landing_header_size">40dp</dimen>
    <dimen name="product_image_size">100dp</dimen>
    <dimen name="stories_image_size">91dp</dimen>
    <dimen name="landing_footer_size">60dp</dimen>
    <dimen name="slide_max_size">140dp</dimen>
    <dimen name="tab_size">100dp</dimen>
    <dimen name="landing_text_size">7sp</dimen>
    <dimen name="landing_grid_view_space">10dp</dimen>

</resources>

When I change my font-size in system settings, the text size does not change in my application. I know I have the right value, because when I change it to say, 10 sp the text gets larger. The project is using api 4.1.2, same as my phone. What could be going wrong? Why isn't the text-size changing?

Community
  • 1
  • 1
  • I'm using sp. Should I be using dip? – user3224332 May 22 '14 at 14:39
  • Where is `textView.setSize()` being called? I don;t see that anywhere... – Karakuri May 22 '14 at 14:41
  • It's further down in the code in a function called initializeGridView. I had put it in my question but it was formatted incorrectly. Sorry about that. The code snippet is between the first big block of code and my xml. – user3224332 May 22 '14 at 14:45
  • 2
    you use dimensions, If I am not mistaking, the size is already scaled. I usually used it this way: `setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.landing_text_size));` – Blackbelt May 22 '14 at 14:51
  • Thanks blackbelt, this actually worked. The problem was, that text was appearing way too large on a nexus phone, while it looked fine on my optimus. I thought it was strange that neither SP nor DP fixed this, so I was just trying to get the text size to be change-able. – user3224332 May 22 '14 at 16:25

1 Answers1

1

I dont have enough reputation points so adding as an answer.. The font size in your application wont change as you have specified in your dimens.xml to use that font size.If you will remove the font size from dimens.xml i think the font size will increase when you increase the system font size.

Dhara Jogi
  • 66
  • 2
  • @user3224332 - Just to add to above, the dimens method used also are for various screens densities. So in order to test the effect of it try to test your app on various emulators or devices. – Atul O Holic May 22 '14 at 14:49