RecyclerView 内容显示不完全 & ScrollView 嵌套 RecyclerView 时自动滚动到底部

目前使用的手机是华为 荣耀7 Android 5.0,数据有7项,但页面上只显示了5项。
解决方法:RecyclerView 外层嵌套 RelativeLayout,并且设置它的属性 android:descendantFocusability="blocksDescendants",使得这个 RecyclerView 强制获取到焦点。相关的属性如下:


图片.png

另:在 ScrollView 中嵌套使用 RecyclerView 会导致页面自动滑到 RecyclerView 的底部。解决方法:自定义继承自 ScrollView 的控件并重写 computeScrollDeltaToGetChildRectOnScreen() 方法 。

    protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
        return 0;
    }

相关的说明:

protected int computeScrollDeltaToGetChildRectOnScreen (Rect rect)

### Compute the amount to scroll in the Y direction in order to get a rectangle completely on the screen (or, if taller than the screen, at least the first screen size chunk of it). 
### 计算Y方向(纵轴)滚动的总合,以便在屏幕上显示子视图的完整矩形(或者,若矩形宽度超过屏幕宽度,至少要填满第一个屏幕大小)

### Parameters

| rect | The rect. |

##### Returns

*   The scroll delta.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容