【发布时间】:2020-10-03 02:20:56
【问题描述】:
Recyclerview 有一个ViewHolder,通常包含TextView。文本内容是可选择的,当长按文本打开选择菜单时。 notifyItemChanged 函数从Adapter 外部调用以调整Textview 字体的大小。调整大小之前可用的文本选择菜单,但之后无法选择项目。长按时不要打开文本选择菜单。没有任何请求不允许事件,但问题出现在notifyItemChanged 之后。
编辑:
问题是Recyclerview的那个item view的TextView xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="15sp" />
问题是解决如果TextView的android:layout_width是WRAP_CONTENT,但一定是MATCH_PARENT,这有什么关系?
回收站视图:
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.ReadBookActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.drawerlayout.widget.DrawerLayout>
Edit-2:
我所有的文本内容都包含许多跨度,并且字体大小有 RelativeSizeSpan。更改字体大小时正在编辑。并使用notifyItemChanged(i) 通知该项目。使用notifyDataSetChanged() 而不在项目中使用Wrap_Content 时不会出现此问题。
Edit-3:问题源于完全编辑RelativeSizeSpan,因为它在更改字体大小时更新为新大小。去掉了更新,现在用的是Textview.setTextSize(),没问题。
【问题讨论】:
-
请发布一个最小可重复的例子
标签: java android android-layout android-recyclerview