0

I have a TextView that starts at '0' and is updated on button press to reflect the current score total, public int points. The TextView does update, but one or more of the characters in the score are truncated (for instance, "1580" might display as "158" or "15"). When the activity is completed and sent to the scoreboard activity, however, the points shown are correct (the variable passed on intent is the same variable points).

Here is my relevant Java code:

public int points = 0;

TextView currentScoreCounter = (TextView) findViewById(R.id.scoreCounter);
currentScoreCounter.setText(String.valueOf(points));

And here is the scoreCounter in my XML file:

<TextView
android:id="@+id/scoreCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="30dp"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true" />

I suspect it may have something to do with the width/height of the TextView, but I am unsure.

Randall Arms
  • 407
  • 1
  • 5
  • 22
  • 1
    You could try [Auto scale TextView to fit within bounds](https://stackoverflow.com/questions/5033012/auto-scale-textview-text-to-fit-within-bounds) – David Rawson Aug 17 '17 at 22:39
  • 1
    is it running into any other part of the UI? – AnthonyK Aug 17 '17 at 22:43
  • @DavidRawson Interesting link, thank you. I think I may be able to work up a solution based on that thread of info. – Randall Arms Aug 17 '17 at 22:44
  • @TonyKutzler I don't think so, it is the only item on its portion of the screen. – Randall Arms Aug 17 '17 at 22:44
  • 1
    Wrap_content should in theory provide enough space, try setting width to match_parent, and see if that changes things. – AnthonyK Aug 17 '17 at 22:46
  • @TonyKutzler Changing the width to `match_parent` does allow the text to fit as the parent's width encompasses the entire width of the screen. This means it is almost certainly the width that is causing the issue, and I will need to find a way to dynamically resize the width. Feel free to make this the answer and I will accept it, should you wish. – Randall Arms Aug 17 '17 at 22:52
  • full xml file please – Shahadat Hossain Shaki Aug 17 '17 at 23:02

1 Answers1

3

You could use android:layout_weight=".60 to cover say 60% of the width, be sure to set android:layout_width="0dp" from my limited testing, that works, but will always be the same static size.

AnthonyK
  • 473
  • 2
  • 11
  • The weight was not being properly resized dynamically, which was cutting off part of the text. Resizing the width manually showed that the TextView's text was indeed being set properly. This is the answer, thank you. – Randall Arms Aug 17 '17 at 23:01