- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
布局设计:
HorizontalScrollView-parent, holding RV[
RecyclerView=>(GridLayoutManager) (orientation verticle)]
这基本上会进行双向滚动。此 UI 专为电视打造。此网格中的焦点行将显示额外的详细信息,而其他行则不会。因此,每当 onFocusChange
中的焦点从一行更改为另一行时,我都会修改 Adapter
的 dataset
并调用 notifyItemRangeChanged()
。
当行的长度超过屏幕的垂直长度(即垂直可滚动)时,这会很好地工作。如果行数较少(例如 4),就会发生崩溃。
错误:
java.lang.IllegalArgumentException: parameter must be a descendant of this view
at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:5937)
at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:5866)
at android.widget.HorizontalScrollView.isWithinDeltaOfScreen(HorizontalScrollView.java:1168)
at android.widget.HorizontalScrollView.onSizeChanged(HorizontalScrollView.java:1569)
at android.view.View.sizeChange(View.java:19719)
at android.view.View.setFrame(View.java:19680)
at android.view.View.layout(View.java:19583)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1780)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1546)
at android.view.View.layout(View.java:19586)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19586)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19586)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
at android.view.View.layout(View.java:19586)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19586)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19586)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19586)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19586)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:758)
at android.view.View.layout(View.java:19586)
at android.view.ViewGroup.layout(ViewGroup.java:6053)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2484)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2200)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
我尝试调用 notifydatasetchange,但这将返回 getAdapterPosition = -1,这不会导致焦点从 1 行更改到另一行
由于适配器代码长度超过了 stackoverflow 设置的字符长度,我为此提供了驱动器链接。 Adapter and viewholder layout code
最佳答案
当 recyclerview 中的项目可聚焦时,我遇到了同样的问题。尝试以下操作:
选项 1 ScrollView 中的用户 windowSoftInputMode="adjustPan"
选项 2将您的自定义 ScrollListener 附加到您的 Activity,目的是当 RV 开始滚动时,清除当前焦点。
protected class FocusableScrollListner implements OnScrollListener {
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// do nothing
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (SCROLL_STATE_TOUCH_SCROLL == scrollState) {
View currentFocus = getCurrentFocus();
if (currentFocus != null) {
currentFocus.clearFocus();
}
}
}
}
选项 3:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View currentFocus = ((Activity)context).getCurrentFocus();
if (currentFocus != null) {
currentFocus.clearFocus();
}
}
根据您的代码,可能还有一些其他选择,您必须清除焦点。
关于android - notifyItemRangeChanged() 导致 RecyclerView Android 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52655667/
我遇到了与 RecyclerView#Adapter 有关 notifyItemRangeChanged 的问题。似乎如果 Adapter 从上次调用 getItemCount 时认为它的大小为 0,
我有一个数据集,它可能会在刷新时发生变化。很难确定现有数据集中的哪些条目已更改。我通读了 recyclerview 适配器说明,我的主要问题是。 确定更改了哪个数据 View ,然后对受影响的范围使用
布局设计: HorizontalScrollView-parent, holding RV[ RecyclerView=>(GridLayoutManager) (orientation ve
精简版 我调用了 adapter.notifyItemRangeChanged(),但看到(通过日志语句)指定范围之外的位置正在重新绑定(bind)。什么可能导致这种情况? 更长的版本 我的应用程序包
我了解 ViewHolder 的 onBindViewHolder 是如何工作的,但是我不清楚 notifyItemRangeChanged(0, this.data.size()); 在此示例中的工
我是一名优秀的程序员,十分优秀!