2012-10-09 75 views
0

我正在開發使用谷歌的地方自動完成一個Android應用程序。安卓:自動填充文本查看

當我從自動完成列表視圖中選擇一個項目時,整個字符串顯示在自動填充文本視圖中,當它不適合一行時,文本視圖會自動變大以適應整個字符串。

我不希望這樣的事情發生,我想文本視圖保持相同的大小,它並不重要,如果整個字符串不能被看到。我怎樣才能做到這一點??

有關自動填充文本視圖的另一個問題。我需要在文本視圖旁邊有一個按鈕,以便用戶可以提交搜索。對於建議列表視圖是唯一的一樣寬,自動完成文本視圖,它沒有填滿屏幕的整個寬度,因爲在文本視圖右側的按鈕。我可以使建議列表視圖填充屏幕的寬度嗎?

回答

2
  1. android:singleLine去作爲參考singleLine
  2. 如果你想建議listview您可以使用這些屬性android:dropDownWidth="xx dp"這裏指android:dropDownWidth。您應該在運行時計算屏幕大小以獲得正確的值。

其他屬性可以幫助您調整下拉列表視圖android:dropDownHorizontalOffsethere

+0

非常感謝!屬性android:dropDownWidth完美。我將值設置爲「match_parent」和下拉列表填充整個屏幕寬度。 – pixie

0

嘗試maxWidth

android:maxWidth 

Makes the TextView be at most this many pixels wide. 

Must be a dimension value, which is a floating point number appended with a unit such 
as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp 
(scaled pixels based on preferred font size), in (inches), mm (millimeters). 

This may also be a reference to a resource (in the form "@[package:]type:name") or 
theme attribute (in the form "?[package:][type:]name") containing a value of this type. 

This corresponds to the global attribute resource symbol maxWidth. 

Related Methods 

setMaxWidth(int) 

編輯 - 您可以使用android:imeOptionsactionGo到 「走出去」 按鈕添加到彈出式鍵盤。

0

我想文本視圖保持相同的大小,它並不重要,如果 整個字符串不能被看作

您可以使用android:singleLine作爲參考singleLine

我可以使建議列表視圖填充屏幕的寬度嗎?

不要以爲你可以通過使用AutoCompleteTextView。你可以去用戶:比爾加里建議,通過增加一個android:imeOptions="actionGo",你可以在軟鍵盤上有一個Go按鈕。然後,在你的活動,增加OnEditorActionListener您AutoCompleteTextView:

actv.setOnEditorActionListener(new OnEditorActionListener() { 

     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
      // TODO Auto-generated method stub 
      if (actionId == EditorInfo.IME_ACTION_GO) { 
       Toast.makeText(MainActivity.this, "GO", Toast.LENGTH_SHORT).show(); 
       return true; 
      } 
      return false; 
     } 
    });