【问题标题】:How to use multiline edittext with Recycler view如何在 Recycler 视图中使用多行编辑文本
【发布时间】:2016-07-20 11:10:14
【问题描述】:

我在 Recycler 视图中使用多行 EditText 作为列表项。我的问题是 EditText 在 Recycler 视图中滚动不顺畅。

以下是我使用的 XML:

对于回收站视图:

 <android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/rec_actions"
                    android:layout_above="@+id/sepp"
                    android:nestedScrollingEnabled="true" />

对于列表项:

<android.support.v4.widget.NestedScrollView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="2"
                android:background="@drawable/commentbox_bgright">

                <EditText
                    android:id="@+id/et_control"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:background="@null"
                    android:gravity="top"
                    android:minLines="4"
                    android:padding="5dp"
                    android:scrollbars="vertical"
                    android:textCursorDrawable="@null"
                    android:textSize="12dp" />
            </android.support.v4.widget.NestedScrollView>

【问题讨论】:

    标签: android android-recyclerview android-nestedscrollview


    【解决方案1】:
    EditTextView.setOnTouchListener { v, _ ->
      v.parent.requestDisallowInterceptTouchEvent(true)
      false
    }
    

    在回收站视图上编辑文本时,请求不向其父级传递触摸事件。这样,editText 将具有触摸事件并按预期运行

    【讨论】:

    • 请不要随便乱扔代码。相反,解释它是如何工作的,以及为什么它是合适的解决方案。我们希望教育不仅仅是回答眼前的问题。
    • 请考虑在您的答案中添加一些解释或细节。虽然它可能会回答问题,但只是添加一段代码作为答案,并不能帮助 OP 或未来的社区成员理解问题或建议的解决方案。
    【解决方案2】:

    我尝试了您的代码。并做了一些小改动。我删除了nestedscrollview 并将edittext 放在相对布局中。滚动工作更顺利地点亮,并且没有注意到任何其他滚动行为变化,因此建议像这样更改您的列表项 xml。

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp">
    
       <EditText
                    android:id="@+id/et_control"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:background="@null"
                    android:gravity="top"
                    android:minLines="4"
                    android:padding="5dp"
                    android:scrollbars="vertical"
                    android:textCursorDrawable="@null"
                    android:textSize="12dp" />
    </RelativeLayout>
    

    【讨论】:

    • 感谢您的回答,但我已经尝试过了,但它不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-30
    • 2022-10-18
    • 1970-01-01
    相关资源
    最近更新 更多