首先,这是我在这里的第一篇文章,我很高兴最终成为stackoverflow的一部分。 :d
我想使用AutoCompleteTextView右侧的按钮构建一个AutoComplete-Search来提交输入字符串。按钮可以具有不同的宽度,本地化或自定义文本(“搜索”,“立即搜索”,......)。我希望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>
在Android中可以找到动态解决方案吗?
祝福, 杰夫
答案 0 :(得分:0)
marginRight
行,交换Button和AutoCompleteTextBox,以便首先定义Button(具有设置宽度的项),然后将AutoCompleteTextBox与Button的ID对齐toLeftOf
。这样就可以了!
<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>