gaara87
gaara87

Reputation: 2077

Spinner down arrow disappears below view background

Down arrow hidden

The following views are inside a ConstraintLayout:

<View android:layout_width="match_parent"
     android:layout_height="0dp"
     android:background="@color/white"
     app:layout_constraintBottom_toBottomOf="@id/pickup_date"
     app:layout_constraintTop_toTopOf="@id/pickup_date" />

<Spinner android:id="@+id/pickup_date"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:spinnerMode="dropdown"
     app:layout_constraintStart_toStartOf="parent"
     app:layout_constraintTop_toBottomOf="@+id/textView3" />

As you can see, it is hiding the down arrow on the spinner.

But when is set the visibility of the View to be gone it looks like this -

Down arrow showing

How do I achieve a white background using the view

Upvotes: 1

Views: 849

Answers (1)

Ferdous Ahamed
Ferdous Ahamed

Reputation: 21756

Remove attribute app:layout_constraintTop_toTopOf="@id/pickup_date" from View.

Try this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="16dp">

    <TextView
        android:id="@+id/textView3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Select a pickup date"
        android:textColor="#000"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="8dp" />

    <Spinner
        android:id="@+id/pickup_date"
        android:layout_width="336dp"
        android:layout_height="wrap_content"
        android:spinnerMode="dropdown"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView3"
        android:layout_marginTop="8dp"
        tools:layout_editor_absoluteX="0dp" />

    <View
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:background="@color/white"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/pickup_date"
        tools:layout_editor_absoluteX="0dp" />

</android.support.constraint.ConstraintLayout>

OUTPUT:

enter image description here

UPDATE:

Your view constrain was not proper.

View attributes app:layout_constraintBottom_toBottomOf="@id/pickup_date" and app:layout_constraintTop_toTopOf="@id/pickup_date", will place View over center position of Spinner.

See documentation for details.

To show spinner over View, do below changes:

1. Add attribute app:layout_constraintTop_toBottomOf="@+id/textView3" to View.

2. Add attribute app:layout_constraintStart_toStartOf="@id/view" to spinner.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="16dp">

    <TextView
        android:id="@+id/textView3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Select a pickup date"
        android:textColor="#000"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="8dp" />

    <View
        android:layout_width="wrap_content"
        android:layout_height="70dp"
        android:background="@color/white"
        android:id="@+id/view"
        tools:layout_editor_absoluteX="0dp"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/textView3" />

    <Spinner
        android:id="@+id/pickup_date"
        android:layout_width="352dp"
        android:layout_height="30dp"
        android:spinnerMode="dropdown"
        app:layout_constraintStart_toStartOf="@id/view"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="33dp" />

</android.support.constraint.ConstraintLayout>

OUTPUT:

enter image description here

Hope this will help~

Upvotes: 1

Related Questions