Sprinner 没有出现在约束布局中 [已解决]

这是我第一次使用微调器,所以我一直在学习教程。 我正在制作将显示对象名称的微调器。

Edit_Form 活动:

class Edit_Form : AppCompatactivity() {
    private lateinit var mySpinner: Spinner
    private lateinit var adapter: ArrayAdapter<Plant_Category>
    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_edit__form)
        mySpinner = findViewById(R.id.spinner3)

        val customObjects = getcustomObjects()
        adapter = ArrayAdapter(this,android.R.layout.simple_spinner_item,customObjects)

        mySpinner.adapter = adapter
    }

    private fun getcustomObjects(): ArrayList<Plant_Category> {
        val customObjects = ArrayList<Plant_Category>()
        customObjects.apply {
            add(Plant_Category(1,"Strawberry","2 times a day","Water more in summer,Can cause irritation to cats"))
            add(Plant_Category(2,"Aloe","2 times a week",Is not safe to digest for pets"))
            add(Plant_Category(3,"Money tree","1-2 times a week","Needs medium to bright indirect light,Safe for pets"))

        }
        return customObjects
    }
}

布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activity.Edit_Form" >

    <EditText
        android:id="@+id/plant_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="100dp"
        android:layout_marginLeft="100dp"
        android:layout_marginTop="135dp"
        android:layout_marginEnd="101dp"
        android:layout_marginRight="101dp"
        android:layout_marginBottom="551dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="@string/edit_name"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:autofillHints="" />

    <Spinner
        android:id="@+id/spinner3"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginStart="60dp"
        android:layout_marginLeft="60dp"
        android:layout_marginTop="73dp"
        android:layout_marginEnd="80dp"
        android:layout_marginRight="80dp"
        android:layout_marginBottom="454dp"
        android:dropDownHeight="100dp"
        android:dropDownWidth="match_parent"
        android:prompt="@string/edit_type"
        android:spinnerMode="dropdown"
        android:theme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/plant_name" />
</androidx.constraintlayout.widget.ConstraintLayout>

数据类:

data class Plant_Category(
        var id: Int =0,var type:String ="",var water_time: String ="",var details: String = ""){

    override fun toString(): String {
        return type
    }
}

问题是 Spinner 在设计模式下显示,但它没有出现在模拟器中,只有输入字段出现。我还更改了背景颜色,以查看可能微调器转到了角落或其他什么地方,但它仍然没有显示。

也许约束布局中的测量有问题,或者我如何实现它?

感谢您的帮助。

thebestme_1 回答:Sprinner 没有出现在约束布局中 [已解决]

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1048.html

大家都在问