Recyclerview
有一个通常包含TextView
的ViewHolder
。文本内容是可选择的,当长时间按下文本时,打开选择菜单。notifyItemChanged
函数从Adapter
外部调用以调整Textview
字体的大小。在调整大小之前可用的文本选择菜单,但在此之后,项是不可选择的。长按压时不要打开文本选择菜单。没有任何不允许事件的请求,但问题发生在notifyItemChanged
之后。
编辑:
问题是回收视图的项目视图的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" />
问题是解决如果android:layout_width
of TextView
是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>
编辑-2:
我所有的文本内容都包装了很多跨度,字体大小有RelativeSizeSpan。它是编辑时,改变字体大小。并使用notifyItemChanged(i)
通知该项。同样,在项目中使用notifyDataSetChanged()
和Wrap_Content
时也不会出现问题。
编辑-3:问题来自于完全编辑RelativeSizeSpan,因为当改变字体大小时,它会以新的大小更新。删除了更新,现在它正在使用Textview.setTextSize(),没有问题。
发布于 2020-06-19 13:05:34
因此,阅读DrawerLayout文档时,它显式地声明:
若要使用DrawerLayout,请将主内容视图定位为宽度和高度为match_parent且没有的第一个子视图。在主内容视图之后添加抽屉作为子视图,并适当地设置layout_gravity。抽屉通常使用match_parent来表示固定宽度的高度。
因此,基本上您的DrawerLayout
不能只包含一个视图,它首先需要有您的主要内容,然后是您的RecyclerView
或其他东西,而RecyclerView
需要有固定的宽度或潜在的wrap_content
。现在,RecyclerView
中的项目可以是您想要的任何内容。
下面是一个示例:
activity_main.xml: (注意到RecyclerView不是第一个项目,它有一个layout_width of wrap_content
)
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</androidx.drawerlayout.widget.DrawerLayout>
app_bar_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include layout="@layout/content_main" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/main_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right|end"
android:layout_margin="16dp"
android:elevation="@dimen/elevation"
app:srcCompat="@drawable/ic_add" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_main">
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_graph" />
</androidx.constraintlayout.widget.ConstraintLayout>
实际上,我还没有亲自测试过它,但是它应该可以工作,因为我有完全相同的设置,但是,我使用的是NavigationView
而不是RecyclerView
,因为我抽屉里有一组物品。
https://stackoverflow.com/questions/62358284
复制相似问题