Android Geek Android Geek - 3 months ago 17
Android Question

How to make a search box not scrolling over scrollview Android

In my home screen I want to add the search box with navigation drawer but I am not able to set the non scrollable edittext over scrollview.

Here is my Code

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#ecedf1">






<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="@dimen/_200sdp" />



<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/_200sdp"
>
<EditText
android:layout_width="@dimen/_280sdp"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/_10sdp"
android:layout_height="@dimen/_40sdp"
android:text="fdgsdfhsfhsfghhsfhsfhf"
android:background="@drawable/customedittext"/>
</RelativeLayout>

<RelativeLayout
android:id="@+id/viewPagerIndicator"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginTop="@dimen/_180sdp"
android:gravity="center">

<LinearLayout
android:id="@+id/viewPagerCountDots"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:gravity="center"
android:orientation="horizontal" />

</RelativeLayout>

<com.information.aanjana.aanjanainformation.NonScrollGridView
android:id="@+id/gv_android"
android:layout_width="@dimen/_299sdp"
android:layout_height="match_parent"
android:horizontalSpacing="8dp"
android:layout_centerHorizontal="true"
android:numColumns="2"
android:paddingLeft="@dimen/_4sdp"
android:paddingRight="@dimen/_4sdp"
android:layout_marginTop="@dimen/_220sdp"
android:verticalSpacing="8dp"/>

</RelativeLayout>

</ScrollView>


<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="@dimen/_170sdp"
android:layout_gravity="start"
app:menu="@menu/drawer"
/>

</android.support.v4.widget.DrawerLayout>


I want a edittext with navigation drawer which should be sticky and do not scroll with rest of the layout. How can I achive it.

What I want is explained in screenshot below:

enter image description here

Answer

Try my below code:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#ecedf1">





<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">


        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="@dimen/_200sdp" />

            <RelativeLayout
                android:id="@+id/viewPagerIndicator"
                android:layout_width="match_parent"
                android:layout_height="25dp"
                android:layout_marginTop="@dimen/_180sdp"
                android:gravity="center">

                <LinearLayout
                    android:id="@+id/viewPagerCountDots"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_centerHorizontal="true"
                    android:gravity="center"
                    android:orientation="horizontal" />

            </RelativeLayout>

            <com.information.aanjana.aanjanainformation.NonScrollGridView
                android:id="@+id/gv_android"
                android:layout_width="@dimen/_299sdp"
                android:layout_height="match_parent"
                android:horizontalSpacing="8dp"
                android:layout_centerHorizontal="true"
                android:numColumns="2"
                android:paddingLeft="@dimen/_4sdp"
                android:paddingRight="@dimen/_4sdp"
                android:layout_marginTop="@dimen/_220sdp"
                android:verticalSpacing="8dp"/>

        </RelativeLayout>

    </ScrollView>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/_200sdp"
        android:layout_alignParentTop="true"
        >
        <EditText
            android:layout_width="@dimen/_280sdp"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/_10sdp"
            android:layout_height="@dimen/_40sdp"
            android:text="fdgsdfhsfhsfghhsfhsfhf"
            android:background="@drawable/customedittext"/>
    </RelativeLayout>

</RelativeLayout>




<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_height="match_parent"
    android:layout_width="@dimen/_170sdp"
    android:layout_gravity="start"
    app:menu="@menu/drawer"
    />

</android.support.v4.widget.DrawerLayout>

Here Only thing which I have changed is kept the editText outside the scrollView.