【发布时间】:2021-07-01 14:48:21
【问题描述】:
我有一个自动完成下拉菜单,它会打开,不仅与文本字段重叠,而且还位于键盘后面。我需要下拉菜单来说明打开时的文本字段和键盘,而不是向下打开键盘和文本字段。由于建议与文本字段重叠,用户无法看到他们正在输入的内容。下面是我的代码
包含自动完成的布局是 selectionList.xml:
<LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android"
p1:orientation="vertical"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="@+id/mainLayout">
<RelativeLayout
p1:orientation="horizontal"
p1:minWidth="25px"
p1:minHeight="25px"
p1:id="@+id/mainLayout2"
p1:background="@drawable/border_full_white_black"
p1:layout_width="match_parent"
p1:layout_height="52dp"
p1:layout_marginLeft="5dp"
p1:layout_marginTop="2dp"
p1:layout_marginRight="5dp"
p1:layout_marginBottom="2dp">
<TextView
p1:layout_width="100dp"
p1:layout_height="match_parent"
p1:id="@+id/label"
p1:textColor="#47463f"
p1:gravity="center"
p1:layout_marginRight="5dp"
p1:layout_marginLeft="5dp"
p1:textAppearance="?android:attr/textAppearanceMedium"
p1:layout_alignParentLeft="true" />
<TextView xmlns:p2="http://schemas.android.com/tools"
p1:textAppearance="?android:attr/textAppearanceSmall"
p1:layout_width="20dp"
p1:layout_height="wrap_content"
p1:id="@+id/required_label"
p1:text="*"
p1:textColor="#F0b323"
p1:gravity="center"
p1:textSize="20dp"
p1:layout_alignParentRight="true"
p1:layout_marginRight="5dp" />
<EditText xmlns:tools="http://schemas.android.com/tools"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/manual_edittext"
p1:gravity="center"
p1:textColor="#47463f"
p1:layout_marginTop="2dp"
p1:layout_marginRight="5dp"
p1:layout_marginBottom="5dp"
p1:background="@drawable/backgroundstyle"
tools:visibility="invisible"
p1:layout_toLeftOf="@+id/required_label"
p1:layout_toEndOf="@+id/user_label" />
<AutoCompleteTextView
p1:id="@+id/autoComplete"
p1:visibility="invisible"
p1:gravity="center"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:layout_marginTop="2dp"
p1:layout_marginRight="2dp"
p1:layout_marginBottom="5dp"
p1:singleLine="true"
p1:imeOptions="actionDone"
p1:popupBackground="#ffffff"
p1:maxLength="2"
p1:dropDownAnchor="@+id/autoComplete"
p1:dropDownHeight="wrap_content"
p1:background="@drawable/border_bottom_lightgray_white"
p1:layout_toLeftOf="@+id/required_label"
p1:layout_toEndOf="@+id/label"
p1:textColor="#47463f"/>
</RelativeLayout>
</LinearLayout>
自动完成布局资源文件为autocomplete_layout.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:p1="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
p1:background="@android:color/white"
p1:layout_width="fill_parent"
p1:layout_height="wrap_content">
<TextView
p1:text="Medium Text"
p1:textAppearance="?android:attr/textAppearanceMedium"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="@+id/textView1"
p1:textColor="#ff000000"
p1:gravity="center"
p1:paddingBottom="8dip"
p1:paddingTop="8dip"
p1:background="@drawable/border_bottom_lightgray_white"
p1:textSize="15dp" />
</LinearLayout>
设置适配器的代码是:
var adapter = new ArrayAdapter<String>(this, Resource.Layout.autocomplete_layout, Resource.Id.textView1, list);
目前下拉菜单重叠如下。
【问题讨论】:
标签: android xml xamarin xamarin.android autocompletetextview