Android 开发过程中技术点整理

1、android设置Activity完全透明使用系统设置
在manifest设置主题theme

android:theme="@android:style/Theme.Translucent.NoTitleBar"

2、recyclerview smoothScrollToPosition()滚动无效问题解决:
自定义LayoutManager类,重写smoothScrollToPosition方法

@Override                                                                                                               
    public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {                 
        LinearSmoothScroller smoothScroller =                                                                               
                new LinearSmoothScroller(recyclerView.getContext()) {                                                       
                    @Override                                                                                               
                    protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {                                 
                        // 返回:滑过1px时经历的时间(ms)。                                                                              
                        return 150f / displayMetrics.densityDpi;                                                            
                    }                                                                                                       
                                                                                                                            
                    @Override                                                                                               
                    public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference) { 
                        return boxStart  - viewStart;                                                                       
                    }                                                                                                       
                };                                                                                                          
                                                                                                                            
        smoothScroller.setTargetPosition(position);                                                                         
        startSmoothScroll(smoothScroller);                                                                                  
    } 

或者也可以这么写

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext) {                                               
    @Override                                                                                                               
    public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {                 
        LinearSmoothScroller smoothScroller =                                                                               
                new LinearSmoothScroller(recyclerView.getContext()) {                                                       
                    @Override                                                                                               
                    protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {                                 
                        // 返回:滑过1px时经历的时间(ms)。                                                                              
                        return 150f / displayMetrics.densityDpi;                                                            
                    }                                                                                                       
                                                                                                                            
                    @Override                                                                                               
                    public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference) { 
                        return boxStart  - viewStart;                                                                       
                    }                                                                                                       
                };                                                                                                          
                                                                                                                            
        smoothScroller.setTargetPosition(position);                                                                         
        startSmoothScroll(smoothScroller);                                                                                  
    }                                                                                                                       
};          

你可能感兴趣的:(Android 开发过程中技术点整理)