How can I fix the spinner widget at the top of the page in Android?

80 views Asked by At

I am using a spinner for drop down in my android app. But, problem is when user scrolls down, the spinner moves up and becomes invisible. I want to fix the spinner at the top of the page so that user can easily select the page.

Here with Scrollbar:

With scroll bar

On scrolling down it disappears:

On Scrolling down

Edit 1: Layout file:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/backgroundColor"
    xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"

    android:scrollbars="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.shiza.dailyquranverses.Quran">


    <Spinner
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/selectChapter">
    </Spinner>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/verse"
        android:maxLines = "2000"
        android:textSize="@dimen/verse_font_chapter"
        android:text="Hello from Quran"
        android:scrollbars="vertical"
        />
    </LinearLayout>
</ScrollView>
1

There are 1 answers

0
Markus Rubey On BEST ANSWER
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Spinner
        android:id="@+id/selectChapter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:scrollbars="vertical"
            tools:context="com.example.shiza.dailyquranverses.Quran">

            <TextView
                android:id="@+id/verse"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:maxLines="2000"
                android:scrollbars="vertical"
                android:text="Hello from Quran" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>