2011-01-27 31 views
1

我在顯示搜索框旁邊的按鈕時遇到問題。我正在使用自動完成的文本視圖,我不知道這是否歸因於自動完成的文本視圖。我怎樣才能解決這個問題。這是我到目前爲止:看不到搜索框旁邊的按鈕android

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    > 

    <AutoCompleteTextView 
     android:id="@+id/autocomplete" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:inputType="text" 
     /> 

    <Button 
     android:id="@+id/search_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Go" 
     /> 

</LinearLayout> 

回答

1

要解決此問題,只需將標記android:layout_weight=1添加到您的AutoCompleteTextView。

發生這種情況是因爲android注意到您在您的AutoCompleteTextView上將layout_width設置爲fill_parent,然後它沒有留下按鈕的空間。將weight設置爲1意味着textview將是「慷慨」的,並且爲他們請求的任何其他組件提供儘可能多的空間,在這種情況下,這僅限於封裝之後Button的寬度。

+0

so android:layout_weight = 1用於使「慷慨」的意見與其他意見分享他們的空間? – madcoderz 2011-01-27 15:10:23

+0

是的。體重值可以是0到1之間的任何值,默認值(如果沒有明確設置,則獲得的值)爲0.如果您給予2視圖相等的權重,他們將嘗試在它們之間平均分配空間。 – Jems 2011-01-27 15:13:06

0

您正在使用AutoCompleteTextView填充父寬度(從而將按鈕從屏幕寬度中推出)。嘗試改變這種

<AutoCompleteTextView 
     android:id="@+id/autocomplete" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:inputType="text" 
     /> 

這個

<AutoCompleteTextView 
     android:id="@+id/autocomplete" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:inputType="text" 
     /> 

而且你的按鈕應該變得可見。這裏有一個很好的資源保存佈局:Android Developer | Declaring Layouts