Slidingmenu 的应用:仿QQ的滑动效果(AboveView缩小)

setContentView(R.layout.qq_above_main);
        
        //getSupportActionBar().setCustomView(R.layout.actionbar_switch);
        getSupportActionBar().setDisplayShowCustomEnabled(true);
        setSlidingActionBarEnabled(true);
        
        
        All = (LinearLayout) this.findViewById(R.id.all);
        slidingmenu = this.getSlidingMenu();
        slidingmenu.setBackgroundDrawable(getResources().getDrawable(R.drawable.background));
        slidingmenu.setBehindWidth(800);//这个用来控制AboveView露出多少的。
        //下面是做重要的部分:
        CanvasTransformer canvas = new CanvasTransformer(){

            @Override
            public void transformCanvas(Canvas canvas, float percentOpen) {
                
                above = new CustomViewAbove(slidingmenu.getContext());//获得了前面的页面
                float scale = (float) (1-percentOpen*0.12); 
                float scalex = (float) (1-percentOpen*0.12);
                //float translations = 
                //在这里面执行前面的menu的动画
                 View aboveview = slidingmenu.getChildAt(1);
               // View behindview = slidingmenu.getChildAt(0);
                if(aboveview != null){
                    afterwidth = (int) (1080 - aboveview.getScrollX() - 1080 * scale);
                    Log.d("array","----getScrollX() = "+afterwidth);
                    if(afterwidth > 0){
                        ViewHelper.setTranslationX(aboveview, afterwidth * scale * 0.12f);
                    }
                    ViewHelper.setScaleX(aboveview, scalex);
                    ViewHelper.setScaleY(aboveview, scale);
                }
                /*int[] location = {0 ,0};
                aboveview.getLocationInWindow(location);
                Log.d("array","location[0] = "+location[0]+"; location[1] = "+location[1]);
                //float leftScale = 1 - 0.3f * scale;
                //float rightScale = 0.8f + scale * 0.2f;
               // canvas.scale(scale, scale, canvas.getWidth()/2, canvas.getHeight()/2); */
            }
            
        };
        
        slidingmenu.setBehindCanvasTransformer(canvas);

我之所以把滑动的过程放到CanvasTransformer()方法中,是因为本人才疏学浅,没找到滑动过程调用的函数,如果有的话麻烦告知我一下。

注意:在缩小aboveview的同时,如果发现aboveview右边空白的话,还要记得将它向右平移,要不然会露出空白部分。

使用slidingmenu可以满足很多想法,省了很多的烦恼。

posted @ 2015-08-11 12:09  黑泡man  阅读(282)  评论(0编辑  收藏  举报