2010-12-02 119 views
0

首先,这是我在这里的第一篇文章,我很高兴成为最终的一部分。 :D动态增长宽度AutoCompleteTextView

我想要使用AutoCompleteTextView右侧的按钮构建一个AutoComplete-Search来提交输入字符串。该按钮可能有不同的宽度,本地化或自定义文本(“搜索”,“现在搜索”,...)。我希望AutoCompleteTextView能够在整个范围内动态增长,直到本地化的搜索按钮。

我目前的计算策略是非常静态的,我必须根据按钮的宽度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> 

是否有可能在android系统找到一个动态的解决方案吗?

有了良好的祝愿, 杰夫

回答

0

是啊,这是一个容易解决。你很接近,只需删除marginRight行,交换Button和AutoCompleteTextBox,以便首先定义Button(具有设置宽度的项目),然后将AutoCompleteTextBox对齐toLeftOf Button的ID。这将会诀窍!

<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 2010-12-02 15:43:15