2017-08-17 33 views
0

我有一個TextView從'0'開始,並更新按鈕按下以反映當前總得分public int points。 TextView會更新,但樂譜中的一個或多個字符會被截斷(例如,「1580」可能會顯示爲「158」或「15」)。但是,當活動完成併發送到記分牌活動時,所顯示的點是正確的(變量傳遞的意圖是相同的變量points)。動態設置TextView與String.valueOf(intVar)截斷intVar的一部分

這裏是我相關的Java代碼:

public int points = 0; 

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

這裏是我的XML文件中的scoreCounter

<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" /> 

我懷疑它可能有一些做的寬度/高度TextView,但我不確定。

+1

你可以嘗試[自動縮放TextView以適合範圍內](https://stackoverflow.com/questions/5033012/auto-scale-textview-text-to-fit-within-bounds) –

+1

是否運行到任何UI的其他部分? –

+0

@DavidRawson有趣的鏈接,謝謝。我想我可能會根據該信息的線索來處理解決方案。 –

回答

3

您可以使用android:layout_weight=".60來覆蓋60%的寬度,請務必在我的有限測試中設置android:layout_width="0dp",該功能有效,但始終是相同的靜態尺寸。

+0

重量未被正確調整大小的動態,這是切斷了部分文本。手動調整寬度顯示TextView的文本確實正確設置。這是答案,謝謝。 –

相關問題