【问题标题】:Android - Spinner arrow does not show when background is imageviewAndroid - 当背景为 imageview 时,微调器箭头不显示
【发布时间】:2017-07-19 20:51:53
【问题描述】:

我有一个简单的布局,我使用 Imageview 作为背景,因为我想使用属性“scaleType”。我将 Imageview 首先放置在我的相对布局中,然后立即放置 Spinner。

微调器箭头不显示。如果我要删除 Imageview 或将我的图像作为背景图像(在相对布局中),它将显示。

这是我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="7dp"
    android:layout_marginRight="7dp">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="matrix"
        android:src="@drawable/background" />

    <Spinner
        android:id="@+id/spinnerGameType"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:spinnerMode="dropdown"
        android:theme="@style/ThemeOverlay.AppCompat.Light" />

</RelativeLayout>

【问题讨论】:

    标签: android android-layout android-imageview android-spinner android-xml


    【解决方案1】:

    添加:

    android:background="@android:drawable/btn_dropdown"
    

    到布局中的 Spinner

     <Spinner
            android:id="@+id/spinnerGameType"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:spinnerMode="dropdown"
            android:background="@android:drawable/btn_dropdown"
            android:theme="@style/ThemeOverlay.AppCompat.Light" />
    

    选项 2:

    为微调器使用带有自定义向下箭头图像的自定义可绘制对象

    在drawable/custom_spinner.xml中

        <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <item>
            <shape>
                <solid android:color="@android:color/transparent" />
    
                <stroke
                    android:width="0dp"
                    android:color="#6f94c7" />
    
                <padding
                    android:bottom="10dp"
                    android:left="2dp"
                    android:right="10dp"
                    android:top="10dp" />
            </shape>
        </item>
        <item>
            <bitmap
                android:gravity="end"
                android:src="@drawable/arrow_down" />  //your image
        </item>
    </layer-list>
    

    现在在 xml 中添加:用于微调器

    android:background="@drawable/custom_spinner"
    

    【讨论】:

    • 添加背景后,我看到了箭头,但材质外观现在已替换为旧的 Spinner 外观。
    • 谢谢。秒选项更好。唯一的问题是点击的连锁反应不起作用。
    • 你知道为什么 ImageView 导致它没有显示在第一位吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多