首页 > 解决方案 > 单击 Spinner1 而不是覆盖在第二个和第三个微调器上

问题描述

单击微调器时,我希望下拉列表不要覆盖在第二个微调器上。而不是第二个微调器应该在下拉列表下方。需要帮助谢谢!

我的微调器 xml 代码

   <Spinner
        android:id="@+id/spinner1"
        style="@style/Widget.AppCompat.Spinner"
        android:layout_width="match_parent"
        android:layout_height="?attr/dropdownListPreferredItemHeight"
        android:dropDownSelector="@drawable/ic_dropdown"

        android:background="@drawable/spinner_bg"
        android:dropDownWidth="match_parent"
        android:dropDownVerticalOffset="?attr/dropdownListPreferredItemHeight"

        android:popupBackground="@android:color/white"
        android:popupElevation="3dp"
        android:stateListAnimator="@drawable/spinner_sla"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <Spinner
        android:id="@+id/spinner2"
        android:layout_marginTop="2dp"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:dropDownVerticalOffset="40dp"
        android:spinnerMode="dropdown"
        android:entries="@array/country_arrays"
        android:prompt="@string/country_prompt"/>
    <Spinner
        android:id="@+id/spinner3"
        android:layout_marginTop="2dp"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:spinnerMode="dropdown" />

标签: androidandroid-studioandroid-layout

解决方案


我建议您使用 ExpandableListView,因为它可以让您下推内容。

<LinearLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ExpandableListView
        android:id="@+id/lvExp"
        android:layout_height="match_parent"
        android:layout_width="match_parent"/>

</LinearLayout>

ExapandableListView 截图

举一个完整的例子,我在Github上上传了一个工作项目


推荐阅读