2010-12-02 9 views
0

まず、これは私の最初の投稿であり、私は最後にstackoverflowの一部になってうれしいです。 :D動的成長幅AutoCompleteTextView

AutoCompleteTextViewの右側にあるボタンでオートコンプリート検索を構築して、入力文字列を送信したいと考えています。ボタンの幅、ローカライズまたはカスタムテキスト(「検索」、「今すぐ検索」など)が異なる場合があります。ローカライズされた検索ボタンまで、AutoCompleteTextViewを動的に拡大したいと思います。

私の現在のapprochは非常に静的であり、私はmarginRightがボタンの幅に応じて変更する必要があります。

<RelativeLayout 
android:id="@+id/layout" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"> 

<AutoCompleteTextView 
android:id="@+id/searchText" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginRight="70dip" 
android:layout_alignParentLeft="true"/> 

<Button 
android:id="@+id/btn" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Search" 
android:layout_alignParentRight="true"/> 

</RelativeLayout> 

が、それはアンドロイドでダイナミックな解決策を見つけることは可能ですか?最高の願いで

、 ジェフ

答えて

0

うん、それは簡単な修正です。あなたは閉じているだけで、marginRight行を削除し、ButtonとAutoCompleteTextBoxを交換して、Button(設定幅のある項目)が最初に定義された後に、ボタンのIDとしてtoLeftOfに合わせてAutoCompleteTextBoxを設定します。これはトリックを行います!

<RelativeLayout 
    android:id="@+id/layout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    >  
    <Button 
     android:id="@+id/btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Search" 
     android:layout_alignParentRight="true" 
     />   
    <AutoCompleteTextView 
     android:id="@+id/searchText" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_toLeftOf="@id/btn" 
     /> 
</RelativeLayout> 
+0

100%満足する回答! :D – Jeffo

+0

笑、それを聞いてうれしい! – kcoppock

+0

余分なクレジットのために、あなたは実際に 'alignParentLeft'行をオフにして、同じ効果で残すことができると思います。 – kcoppock

関連する問題