微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用Kotlin单击editText时如何修复NestedScrollView

如何解决用Kotlin单击editText时如何修复NestedScrollView

我有一个nestedScrollView,其中包含很多组件,例如recyclerview,viewPager ... 我有一个editText用于搜索,还有一个包含搜索图标的AppBar。当我单击搜索图标时,editText slideDown,当我第二次单击它时slideUP。 我的问题是,例如,当我向下滚动活动时,当我单击搜索editText时,活动未固定,请向上移动并移出屏幕。 这是main_activity.xml代码

<LinearLayout 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:background="@color/grey"
        android:fitsSystemWindows="false"
        android:orientation="vertical">

    <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/whiteFour"
            android:paddingTop="@dimen/spacing_medium"
            android:paddingBottom="@dimen/spacing_medium"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            <androidx.appcompat.widget.AppCompatimageView
                    android:id="@+id/searchButtonMain"
                    android:layout_width="30dp"
                    android:layout_height="28dp"
                    android:layout_marginEnd="@dimen/spacing_middle"
                    android:adjustViewBounds="true"
                    android:tint="@color/black"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toStartOf="@+id/Chart"
                    app:layout_constraintTop_toTopOf="parent"
                    app:srcCompat="@drawable/ic_search" />
           <.....>


        </androidx.constraintlayout.widget.ConstraintLayout>

    </com.google.android.material.appbar.AppBarLayout>

    <LinearLayout
            android:id="@+id/lytSearchView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/whiteFour"
            android:visibility="gone"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0">

        <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/searchFields"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="20dp"
                android:layout_marginBottom="10dp"
                android:background="@drawable/border"
                android:drawableStart="@drawable/icn_search_x"
                android:drawablePadding="@dimen/spacing_large"
                android:fontFamily="@font/cairo"
                android:gravity="left"
                android:hint="@string/search_product"
                android:inputType="text"
                android:lineHeight="18dp"
                android:maxLines="1"
                android:paddingStart="15dp"
                android:paddingTop="5dp"
                android:paddingEnd="15dp"
                android:paddingBottom="5dp"
                android:textColorHint="@color/greyish"
                android:textSize="14sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0" />


    </LinearLayout>


    <androidx.core.widget.nestedScrollView
            android:id="@+id/nestedScrollView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/grey"
            android:clipToPadding="true"
            android:fillViewport="true"
            android:scrollbars="none"
            android:scrollingCache="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/appBarLayout">
<................> 

当我单击搜索按钮时:

 searchButtonMain.setonClickListener {
            if (firstClickSearch) {
                val animation = AnimationUtils.loadAnimation(
                    this,R.anim.slide_up
                )
                 //appending animation to textView
                lytSearchView.startAnimation(animation)
                lytSearchView.visibility = View.GONE
                firstClickSearch = false
            } else {
                 val animation = AnimationUtils.loadAnimation(
                    this,R.anim.slide_down
                )

                //appending animation to textView
                lytSearchView.startAnimation(animation)
                lytSearchView.visibility = View.VISIBLE
                firstClickSearch = true
            }

      
        }

所以,当用Kotlin单击search editText时,我该怎么做才能修复nestedScrollView

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。