android焦点问题处理以及需要点击两次才能选中问题以及滚到顶有时候无效问题探讨...

我发现不做笔记,会反复踩在同样一个坑

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;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值