How to scroll an EditText to the very top of the layout?

前端 未结 1 1461
深忆病人
深忆病人 2020-12-12 04:12

So I have this layout with some ChipsInput inside a scrollview and I simply want these to go to the very top when the keyboard is activated

I\'ve tried to change win

相关标签:
1条回答
  • 2020-12-12 04:23

    You can use CoordinatorLayout as your root and NestedScrolView in it .

    CoordinatorLayout as root reacts to keyboard and scrolls your layout to the top of your phone with assistant of NestedScrollView which your NestedScrollView includes your layout code .

    To put the issue into perspective view

    CoordinaterLayout > NestedScrolView > yourLayout

    Change your layout XMl like code below

    <android.support.design.widget.CoordinatorLayout
        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.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <LinearLayout
                android:id="@+id/constraintLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/background1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:orientation="vertical">
            <!-- rest of your layout xml code-->
    
        </android.support.v4.widget.NestedScrollView>
    </android.support.design.widget.CoordinatorLayout>
    
    0 讨论(0)
提交回复
热议问题