Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android spinner arrow always above other views

In my app, I have some spinners (each of which is part of a fragment) in a scrollView. This scrollView is placed below a textView.

The problem is that, when I'm running the app on my test device (Samsung Galaxy S6 Edge [G925F], API 23), the little arrow of the spinner stays visible above the textView, even though the rest of the spinner is already out of view.

I did a lot of research but couldn't find any solutions, so I'm asking here: What do I need to do so that the arrows disappear like the rest of the spinner?

Here some pictures:

In this picture, you can see the textView at the top of the activity and below the spinners, before I scrolled down

In this screenshot, you can see the problem. The little triangles of the spinner are still visible, but the spinner itself is already scrolled out of view.

Here is the XML code of the fragment containing the spinner:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout
    android:id="@+id/fragLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/gradeDisplay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="15dp"
        android:layout_marginLeft="15dp"
        android:text="1"
        android:textSize="30dp"/>
    <Spinner
        android:id="@+id/spinner"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="30dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:entries="@array/grades"/>
    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:layout_marginEnd="15dp"
        android:layout_marginRight="15dp"
        android:src="@drawable/ic_remove_black_24dp"
        android:background="@null"/>
</LinearLayout>
<Space
    android:layout_width="0dp"
    android:layout_height="5dp"
    android:layout_below="@id/fragLayout"/>
</RelativeLayout>

And here is the code of the MainActivitys content:

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="de.jeanma.android.avo.MainActivity"
tools:showIn="@layout/activity_main">
    <Space
        android:id="@+id/mainContentSpace"
        android:layout_width="match_parent"
        android:layout_height="16dp" />
    <TextView
        android:id="@+id/textView"
        android:layout_below="@id/mainContentSpace"
        android:layout_width="match_parent"
        android:text="Standard text"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:gravity="end"/>
    <ScrollView
        android:id="@+id/scrollView"
        android:layout_below="@id/textView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:id="@+id/layout"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:divider="@drawable/divider"
            android:showDividers="middle">
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

The fragments are added to the LinearLayout (@id/layout) by a Java method. If needed, I will post that here as well.

I'm using Java 1.8.05 and the target SDK is 23, the minimum is 14. The code is written in Android Studio

The textView with the problems is the @id/textView, displaying the large number at the top.

like image 474
Jeanma Avatar asked Mar 22 '16 23:03

Jeanma


1 Answers

@jeanma you can fix the issue with just setting

android:background="#00FFFFFF"

for your ScrollView or root LinearLayout of the ScrollView

like image 79
Kirill Vashilo Avatar answered Oct 14 '22 01:10

Kirill Vashilo