2013-08-24 34 views
3

我正在使用NumberPicker並顯示String的值。這裏是例子:如何使NumberPicker文本區域變寬?

odaberiRazinu.setVisibility(View.VISIBLE); 
odaberiRazinu.setMinValue(0); 
odaberiRazinu.setMaxValue(3); 

odaberiRazinu.setDisplayedValues(new String[] { "FirstAnswer", "SecondAnswer", "ThirdAnswer", "FourthAnswer"}); 

我有問題,因爲從FirstAnswer,只有它是唯一可見的「stAnsw」(類似的東西)。當我移動它時,它有時會變寬,但效果不好。

有沒有辦法讓顯示區域更寬或者是否有更好的方法來製作-like機制Strings

EDIT(這是XML佈局):

<NumberPicker 
     android:id="@+id/section_numberPicker" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
/> 

回答

1

此代碼對我的作品。 NumberPicker與最長的項目文本一樣寬。也許你必須爲父級佈局選擇不同的大小。

<FrameLayout 
    android:id="@+id/content_frame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <NumberPicker 
     android:id="@+id/section_numberPicker" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     /> 

</FrameLayout> 

enter image description here

您也可以設置一個靜態widht android:layout_width="300dp"但隨後將截斷文本IFI是更長的時間。