Carson Holzheimer
Carson Holzheimer

Reputation: 2962

Allow nested scrolling at the same time as allowing edit text to expand a little (xml)

What I want is to be able to have an EditText that can expand from say 5 to 10 lines of text. When it reaches 10 lines, then it starts to scroll, in a nested manner. i.e. When the limit of the edit text scroll is reached, then the outer page view can be scrolled. What I've tried so far is this but it doesn't allow nested scrolling:

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

        <EditText
            android:id="@+id/edit_description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:maxLines="10"
            android:background="@android:color/transparent"
            android:gravity="top"
            android:paddingStart="12dp"
            android:paddingEnd="12dp"
            android:textSize="15sp"
            tools:text="Some description \n\n\n\n\n asdf \n asdf \n \n adsf \n asdf \n asdf \n asdf \n asfd " />
</androidx.core.widget.NestedScrollView>

However it does work if I set a specific layout height on the NesteScrollView, but then that won't allow the EditText to expand.

Also. I'd prefer not to use code for this. I know it's possible overriding touch events etc but I'm looking for a cleaner approach.

Upvotes: 1

Views: 118

Answers (1)

tobiasfried
tobiasfried

Reputation: 1852

Try allowing the EditText to be a scroll container, and make sure it notifies its parent NestedScrollView:

android:isScrollContainer="true"       
android:nestedScrollingEnabled="true"

Upvotes: 1

Related Questions