我发现不做笔记,会反复踩在同样一个坑
android:descendantFocusability=”blocksDescendants”
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
举例1:
我在做自定义RadioButton的时候哪怕父亲直接拦截给自己处理,结果要点击两次才能到顶,感觉应该是焦点问题导致
https://blog.csdn.net/hejjunlin/article/details/52263256
但是经过调试发现 其实点击事件已经触发,到顶刷新的时候有时候scrollToPosition没有效果,这是怎么回事呢??
public static void scrollTop(RecyclerView recyclerview, NestedScrollView scrollView) {
if (scrollView != null) {
scrollView.smoothScrollTo(0, 0);
}
if (recyclerview != null) {
// recyclerview.smoothScrollToPosition(0);
// recyclerview.smoothScrollToPosition(0);
recyclerview.scrollToPosition(0);
}
}
关键问题在于scrollView
的直接scrollTo
有毛病,改成smoothScrollTo
百分之百可以滚动到顶部了
而为了解决这个以为是焦点的问题,我写了这么多代码
binding.radioBtn1.getRadioButtonWrap().setFocusable(false);
binding.radioBtn1.getRadioButtonWrap().setFocusableInTouchMode(false);
binding.radioBtn1.getTopImageView().setFocusable(false);
binding.radioBtn1.getTopImageView().setFocusableInTouchMode(false);
binding.radioBtn1.getRadioButton().setFocusable(false);
binding.radioBtn1.getRadioButton().setFocusableInTouchMode(false);
甚至还拦截所有事件
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return true;
}