【问题标题】:InputType in EditText inside RecyclerViewRecyclerView 内 EditText 中的 InputType
【发布时间】:2018-04-23 07:57:13
【问题描述】:

在我的RecyclerrView 中,有些项目有EditText(Inside cardView)。它可以在EditText 中不定义InputType 的情况下正常工作,但是当我定义 InputType 时,它​​会导致recyclerviewEditText 成为焦点时滚动到零位置(当触摸editText 输入值时)。

这是一个默认的EditText,可以正常工作

 <EditText
        android:id="@+id/et_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/dp_5"
        android:layout_weight="1"
        android:background="@drawable/box_blue_outline"
        android:gravity="center"
        android:hint="@string/name"
        android:padding="@dimen/dp_5"
        android:textSize="@dimen/sp_16" />

我还有一个只接受数字的EditText,所以我添加了InputType

  <EditText
    android:id="@+id/et_name"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/dp_5"
    android:layout_weight="1"
    android:background="@drawable/box_blue_outline"
    android:gravity="center"
    android:inputType="number"
    android:hint="@string/number"
    android:padding="@dimen/dp_5"
    android:textSize="@dimen/sp_16" />

但是点击这个EditText 输入值,它在RecyclerView 之间有某个位置(比如7),它会滚动回位置1。

【问题讨论】:

  • 如果你有一个EditText 在 0 位置,当它获得焦点时它应该滚动到 0 位置。究竟是什么问题?请用一些代码启发我们。
  • 添加一些代码....以便我们可以看到您如何在回收站视图中呈现数据
  • 添加所有涉及的代码并不容易,但我正在添加所有有助于理解问题的代码

标签: android android-recyclerview android-edittext android-inputtype


【解决方案1】:

看起来,不同的键盘更改会导致 RecyclerView 更新。 Window 焦点类型很有可能。尝试更改出现在 Activity/Fragment onCreate 中的键盘行为。

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

请包括所有View 布局、RecyclerView 的位置以及您要绑定的布局。

【讨论】:

    猜你喜欢
    • 2011-07-01
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    相关资源
    最近更新 更多