如何使搜索框不在 scrollview 上滚动 Android

How to make a search box not scrolling over scrollview Android

在我的主屏幕中,我想添加带导航抽屉的搜索框,但我无法在滚动视图上设置不可滚动的编辑文本。

这是我的代码

<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>

我想要一个带有导航抽屉的编辑文本,它应该是粘性的并且不会随着布局的其余部分滚动。我怎样才能实现它。

我想要的在下面的截图中有解释:

要不你试试把它放到ScrollView外面吧。然后用 RelativeLayout 覆盖它并将重力设置为 top。我现在不能 运行 但在 xml 应该看起来像这样

<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: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>

<!-- Here we add the layout outside the ScrollView -->

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/_200sdp"
        android:gravity="top"> <!-- GRAVITY ADJUST -->

        <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>



<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>

希望它 运行 顺利并有所帮助。

试试我下面的代码:

<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>

这里我唯一改变的是 editTextscrollView 之外。