Java 如何移动微调器下拉菜单以查看选定选项?

Java 如何移动微调器下拉菜单以查看选定选项?,java,android,xml,android-spinner,Java,Android,Xml,Android Spinner,我正在使用微调器,并用所有选项填充下拉菜单。我的问题是,当下拉菜单出现时,它会阻止当前选择的内容 下面是一张要演示的图片和我的代码: if(field.getType().equalsIgnoreCase(“选择”)) { CSSelect=(CSSelect)字段; LinearLayout ll=新的LinearLayout(本); 最终微调器s=新微调器(此); TextView t=新的TextView(此); t、 setText(“▼"); t、 setTextSize(12);

我正在使用微调器,并用所有选项填充下拉菜单。我的问题是,当下拉菜单出现时,它会阻止当前选择的内容

下面是一张要演示的图片和我的代码:

if(field.getType().equalsIgnoreCase(“选择”))
{
CSSelect=(CSSelect)字段;
LinearLayout ll=新的LinearLayout(本);
最终微调器s=新微调器(此);
TextView t=新的TextView(此);
t、 setText(“▼");
t、 setTextSize(12);
t、 退耕地资源(R.drawable.spinnerbg);
t、 setOnClickListener(新视图。OnClickListener(){
@凌驾
公共void onClick(视图v){
s、 performClick();
}
});
LinearLayout.LayoutParams slp=新的LinearLayout.LayoutParams(400,LinearLayout.LayoutParams.WRAP_内容);
s、 setLayoutParams(slp);
ll.addView(s);
ll.addView(t);
s、 退耕地资源(R.drawable.spinnerbg);
列表=新的ArrayList();
JSONArray choices=select.getChoices();
对于(int j=0;j
微调器下拉列表项xml:

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textSize="12dp"
android:textColor="#000000"/>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#000000"

/>

微调器项xml:

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textSize="12dp"
android:textColor="#000000"/>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#000000"

/>


如何从上面的A转到B?使用什么代码移动下面的下拉菜单?

将微调器模式从对话框设置为下拉菜单:

 <Spinner 
        android:id="@+id/tv_power_settings_type_spinner" 
        style="@android:style/Widget.Spinner"
        android:spinnerMode="dropdown"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:popupBackground="@color/black"/>

将微调器模式从对话框设置为下拉列表:

 <Spinner 
        android:id="@+id/tv_power_settings_type_spinner" 
        style="@android:style/Widget.Spinner"
        android:spinnerMode="dropdown"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:popupBackground="@color/black"/>

只需将以下属性添加到XML中的微调器:


android:OverlapsAnchor=“false”

只需在XML中向微调器添加以下属性:


android:OverlapsAnchor=“false”

您当前放置此菜单的代码是什么?您当前放置此菜单的代码是什么?将微调器模式设置为下拉的java等价物是什么?我必须动态创建微调器。我看到setLayoutMode(…)但我不知道要传递什么参数才能使其成为下拉列表。我只是尝试了一下,但问题仍然存在(仍然阻止所选的选项)。我非常感谢您的帮助,因此我向上添加了1。您是否更改了构造函数?是的,我将其更改为最终微调器s=新微调器(此为微调器.MODE\u下拉列表);但下拉菜单仍然覆盖选定的选项。将微调器模式设置为dropdown的java等价物是什么?我必须动态创建微调器。我看到setLayoutMode(…),但我不知道传递什么参数才能使其成为下拉菜单。我只是尝试了一下,但问题仍然存在(仍然阻止选定的选项)。非常感谢您的帮助,所以我选择了1。您是否更改了构造函数?是的,我将其更改为最终微调器s=新微调器(这是Spinner.MODE_下拉菜单);但下拉菜单仍然覆盖选定的选项。