Android 如何将列表视图设置为全宽?
我有一个带有自动完成文本视图的活动,一个添加按钮和一个列表视图,当用户输入时会弹出 在xml中:Android 如何将列表视图设置为全宽?,android,android-layout,android-listview,Android,Android Layout,Android Listview,我有一个带有自动完成文本视图的活动,一个添加按钮和一个列表视图,当用户输入时会弹出 在xml中: <Button android:id="@+id/locationButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:minWidth="46dip"
<Button
android:id="@+id/locationButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:minWidth="46dip"
android:onClick="getLocation"
android:text="@string/icon_map_marker" />
<AutoCompleteTextView
android:id="@+id/autocomplete_city"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:dropDownVerticalOffset="0.2dp"
android:hint="@string/city_hint"
android:inputType="text"
android:layout_alignBottom="@+id/locationButton"
android:layout_alignTop="@id/locationButton"
android:layout_toLeftOf="@id/locationButton"/>
问题在于,由自动完成过程创建的listview与自动完成文本视图的宽度相同。但是,它应该具有全宽,包括按钮的宽度(见图)。有什么办法吗?在另一个布局下创建列表视图,执行以下操作:
<LinearLayout>
android:width="fill_parent"
android:height="fill_parent"
android:orientation="vertical"
<LinearLayout>
android:orientation="horizontal"
...
<AutoCompleteTextView> ... </AutoCompleteTextView>
<Button> ... </Button>
</LinearLayout>
<ListView>
...
android:width="fill_parent"
android:height="fill_parent"
</ListView>
</LinearLayout>
android:width=“填充父对象”
android:height=“填充父对象”
android:orientation=“垂直”
android:orientation=“水平”
...
...
...
...
android:width=“填充父对象”
android:height=“填充父对象”
希望这有帮助(:使用locationButton删除AutoCompleteTextView中的对齐,然后尝试将其调整为全宽。使用此布局。我已尝试并检查过。这很有帮助
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100">
<AutoCompleteTextView
android:id="@+id/autocomplete_city"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="70"
android:dropDownVerticalOffset="0.2dp"
android:hint="city_hint"
android:inputType="text"/>
<Button
android:id="@+id/locationButton"
android:layout_width="0dp"
android:layout_weight="30"
android:layout_height="wrap_content"
android:minWidth="46dip"
android:onClick="getLocation"
android:text="icon" />
</LinearLayout>
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
找到了答案:
背景
android:dropDownWidth="match_parent"
在autocomplete textview上解决了这个问题。我不能用xml声明listview,因为它是由autocomplete textview自动生成的弹出窗口