Android 动态增长宽度AutoCompleteTextView
首先,这是我在这里的第一篇文章,我很高兴成为stackoverflow的一部分,最后:D 我想用AutoCompleteTextView右侧的按钮构建一个自动完成搜索,以提交输入字符串。按钮可能有不同的宽度,因为本地化或自定义文本搜索,现在搜索,。。。。我希望AutoCompleteTextView在整个过程中动态增长,直到使用本地化搜索按钮 我当前的方法是非常静态的,我必须根据按钮的宽度更改边距:Android 动态增长宽度AutoCompleteTextView,android,width,Android,Width,首先,这是我在这里的第一篇文章,我很高兴成为stackoverflow的一部分,最后:D 我想用AutoCompleteTextView右侧的按钮构建一个自动完成搜索,以提交输入字符串。按钮可能有不同的宽度,因为本地化或自定义文本搜索,现在搜索,。。。。我希望AutoCompleteTextView在整个过程中动态增长,直到使用本地化搜索按钮 我当前的方法是非常静态的,我必须根据按钮的宽度更改边距: <RelativeLayout android:id="@+id/layout" andr
<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中是否有可能找到一个动态解决方案
致以最良好的祝愿,
杰夫是的,这很容易解决。你很接近了,只需移除右边的边线,交换按钮和AutoCompleteTextBox,以便首先定义具有设置宽度的项的按钮,然后将AutoCompleteTextBox设置为与按钮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>
为了获得额外的积分,我认为你实际上可以去掉左行,效果也是一样的。