我發(fā)現(xiàn)不做筆記,會(huì)反復(fù)踩在同樣一個(gè)坑
android:descendantFocusability=”blocksDescendants”
beforeDescendants:viewgroup會(huì)優(yōu)先其子類控件而獲取到焦點(diǎn)
afterDescendants:viewgroup只有當(dāng)其子類控件不需要獲取焦點(diǎn)時(shí)才獲取焦點(diǎn)
blocksDescendants:viewgroup會(huì)覆蓋子類控件而直接獲得焦點(diǎn)
舉例1:
我在做自定義RadioButton的時(shí)候哪怕父親直接攔截給自己處理,結(jié)果要點(diǎn)擊兩次才能到頂遣耍,感覺應(yīng)該是焦點(diǎn)問題導(dǎo)致
https://blog.csdn.net/hejjunlin/article/details/52263256
但是經(jīng)過調(diào)試發(fā)現(xiàn) 其實(shí)點(diǎn)擊事件已經(jīng)觸發(fā),到頂刷新的時(shí)候有時(shí)候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);
}
}
關(guān)鍵問題在于scrollView
的直接scrollTo
有毛病豫领,改成smoothScrollTo
百分之百可以滾動(dòng)到頂部了
而為了解決這個(gè)以為是焦點(diǎn)的問題,我寫了這么多代碼
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;
}