开发者

Dynamic Growing-Width AutoCompleteTextView

First of all, this is my first post here and i´m happy to be a part of stackoverflow, finally. :D

I want to build a AutoComplete-Search with a button on the right of the AutoCompleteTextView to submit the input string. The button may have different widths, cuz of localization or custom texts ("search", "search it now",...). I want the AutoCompleteTextView growing dynamically over the full with until the localized search button.

My current approch is very static and i have to change the marginRight depending on the width of the button:

<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_conte开发者_Go百科nt"
android:text="Search"
android:layout_alignParentRight="true"/>

</RelativeLayout>

Is it possible in android to find a dynamic solution?

With best wishes, Jeff


Yup, that's an easy fix. You're close, just remove the marginRight line, swap the Button and AutoCompleteTextBox so that the Button (the item with a set width) is defined first, then set the AutoCompleteTextBox aligned toLeftOf the Button's ID. This will do the trick!

<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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜