允许嵌套滚动同时允许编辑文本扩展一点(xml)

问题描述 投票:1回答:1

我想要的是能够拥有一个可以从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 \n\n\n\n\n asdf \n asdf \n \n adsf \n asdf \n asdf \n asdf \n asfd " />
</androidx.core.widget.NestedScrollView>

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

也。我不想为此使用代码。我知道它可能会覆盖触摸事件等,但我正在寻找一种更清洁的方法。

android android-layout android-nestedscrollview
1个回答
1
投票

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

android:isScrollContainer="true"       
android:nestedScrollingEnabled="true"
© www.soinside.com 2019 - 2024. All rights reserved.