当前位置: 主页 > 开源代码 >

高仿网易云音乐客户端的Home页面切换Tabhost

分享

介绍:

高仿网易云音乐客户端的Home页面切换Tabhost,并且三角形是透明的,
实现方式,自定义AnimTabsView继承 RelativeLayout 里面对当前选中的item 处理 三角形变成透明效果,
即在onDraw 里面对三角形图片经行透明度处理,AnimTabsView提供 setOnAnimTabsItemViewChangeListener
方法的onChange()用来监听点击切换tabhost.

下面主要是AnimTabsView里面的onDraw()实现的,部分代码如下:

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if ((this.mScroller == null) || (!this.mScroller.computeScrollOffset())) {
            this.mLeftDrawRect.set(0, this.mCurrentSlideY, this.mCurrentSlideX, this.mCurrentSlideY + this.mShadow.getHeight());
            canvas.drawBitmap(this.mShadow, null, this.mLeftDrawRect, null);
            this.mRightDrawRect.set(this.mCurrentSlideX + this.mSlideIcon.getWidth(), this.mCurrentSlideY, getWidth(), this.mCurrentSlideY
                    + this.mShadow.getHeight());
            canvas.drawBitmap(this.mShadow, null, this.mRightDrawRect, null);
            canvas.drawBitmap(this.mSlideIcon, this.mCurrentSlideX, this.mCurrentSlideY, null);
            return;
        }
        int scrollX = this.mScroller.getCurrX();
        int scrollY = this.mScroller.getCurrY();
        this.mLeftDrawRect.set(0, scrollY, scrollX, scrollY + this.mShadow.getHeight());
        canvas.drawBitmap(this.mShadow, null, this.mLeftDrawRect, null);
        this.mRightDrawRect.set(scrollX + this.mSlideIcon.getWidth(), scrollY, getWidth(),
                scrollY + this.mShadow.getHeight());
        canvas.drawBitmap(this.mShadow, null, this.mRightDrawRect, null);
        canvas.drawBitmap(this.mSlideIcon, scrollX, scrollY, null);
        invalidate();
    }

运行效果: