Android 直播聊天界面来消息缓慢向上滑动效果、头部渐变消失

使用自定义

LinearLayoutManager

继承

LinearLayoutManager

覆盖

@Override
    public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
        MyLinearSmoothScroller.setTime(300f);
        MyLinearSmoothScroller scroller = new MyLinearSmoothScroller(recyclerView.getContext(), scrollType);
        scroller.setTargetPosition(position);
        startSmoothScroll(scroller);
    }

自定义

LinearSmoothScroller
@Override
    protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
        return 300 / displayMetrics.densityDpi;
    }

使用

recyclerView.smoothScrollToPosition(listData.size - 1)

头部渐变消失效果

自定义recycleview

    @NonNull
    @Override
    public EdgeEffectFactory getEdgeEffectFactory() {
        return new EdgeEffectFactory(){
            @NonNull

你可能感兴趣的:(Android基础,android,android,studio,java)