TV开发中ScrollView嵌套ListView的问题

ScrollView嵌套ListView焦点移动ListView不滚动的问题

当焦点在GridView上移动时,焦点已经移动到屏幕外,但是ScrollView不会跟随滚动。

即使在ListView的keydown事件中调用scrollview的executeKeyEvent方法仍然不行,

View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);

上一方法根本找不到下一个焦点view。看来只能自己手动滚动了,scrollview的滚动可以调用scrollBy,如果想平滑滚动那就调用smoothScrollBy
onItemSelected函数中进行滚动方向的判断,滚动距离的计算;需要知道ScrollView的最大高度,记录上一次滚动位置。代码如下:

         myListView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                int top = view.getTop();
                int bottom = view.getBottom();
                if (position > lastPos) {
                    if (bottom > bottomLimit) {
                        int height = bottom - bottomLimit;
                        bottomLimit += height;
                        scrollView.scrollBy(0, height);
                    }
                }
                else if(position < lastPos){
                    if (bottomLimit - top > screenHeight) {
                        int height = bottomLimit - top - screenHeight;
                        bottomLimit -= height;
                        scrollView.scrollBy(0, -(height));
                    }
                }
                lastPos = position;
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

bottomLimit初始值就是Scrollview的高度;
嵌套GridView类似;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值