android 底部滚动选项栏

先上效果图

ezgif.com-video-to-gif (1).gif

需求1:底部滚动栏最多展示6条数据,若选中数据在6条之后,自动滚动到选中数据项
mRecyclerView.smoothScrollToPosition(i);
需求2:popupwindow弹出动画前整个页面效果变暗
在popupwindow show()方法前调用setBackgroundAlpha(activity,0.6f),在dismiss方法前调用 setBackgroundAlpha(activity,1f)将透明度还原
`

    public static void setBackgroundAlpha(Activity activity,float bgAlpha) {
    WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
    lp.alpha = bgAlpha; //0.0-1.0
    //解决华为手机设置背景色无效
    if (bgAlpha == 1) {
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);//不移除该Flag的话,在有视频的页面上的视频会出现黑屏的bug
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);//此行代码主要是解决在华为手机上半透明效果无效的bug
    }
    activity.getWindow().setAttributes(lp);
}`  

需求3:底部滚动栏最多展示6条数据,若小于6条列表自适应高度
重写recyclerView LayoutManager的onMeasure方法,当小于6条是显示list高度
`

  //默认显示6条,超过6条滑动显示
    mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity) {
        @Override
        public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
            int count = getChildCount();
            if (count > 0 && count <= 6) {
                View firstChildView = recycler.getViewForPosition(0);
                measureChild(firstChildView, widthSpec, heightSpec);
                setMeasuredDimension(View.MeasureSpec.getSize(widthSpec), firstChildView.getMeasuredHeight() * count);
            } else {
                super.onMeasure(recycler, state, widthSpec, heightSpec);
            }
        }
    });`

你可能感兴趣的:(android 底部滚动选项栏)