允许嵌套滚动,同时允许编辑文本稍微展开一点 (xml)



我想要的是能够有一个可以从5行文本扩展到10行文本的EditText。当它达到 10 行时,它开始以嵌套方式滚动。即,当达到编辑文本滚动的限制时,可以滚动外页视图。到目前为止,我尝试的是这个,但它不允许嵌套滚动:

<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 nnnnn asdf n asdf n n adsf n asdf n asdf n asdf n asfd " />
</androidx.core.widget.NestedScrollView>

但是,如果我在NesteScrollView上设置特定的布局高度,它确实有效,但这不允许EditText展开。

也。我宁愿不为此使用代码。我知道可以覆盖触摸事件等,但我正在寻找一种更干净的方法。

尝试允许EditText成为滚动容器,并确保它通知其父级 NestedScrollView:

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

最新更新