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

1.高仿网易云音乐客户端的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();
    }

运行效果:

 

 

 

2.FlipViewPager 对item实现左右对折滑动翻页效果

FlipViewPager 对每一条item实现左右对折滑动翻页效果,解决左右滑动和上下滑动的事件分发处理机制。
内部实现如下:用ListView试下,对listview设置adapter,这个adapter继承BaseFlipAdapter<Friend>
,然后对每一个item进行view处理,部分
代码如下:
class FriendsAdapter extends BaseFlipAdapter<Friend> {

        private final int PAGES = 3;
        private int[] IDS_INTEREST = {R.id.interest_1, R.id.interest_2, R.id.interest_3, R.id.interest_4, R.id.interest_5};

        public FriendsAdapter(Context context, List<Friend> items, FlipSettings settings) {
            super(context, items, settings);
        }

        @Override
        public View getPage(int position, View convertView, ViewGroup parent, Friend friend1, Friend friend2) {
            final FriendsHolder holder;

            if (convertView == null) {
                holder = new FriendsHolder();
                convertView = getLayoutInflater().inflate(R.layout.friends_merge_page, parent, false);
                holder.leftAvatar = (ImageView) convertView.findViewById(R.id.first);
                holder.rightAvatar = (ImageView) convertView.findViewById(R.id.second);
                holder.infoPage = getLayoutInflater().inflate(R.layout.friends_info, parent, false);
                holder.nickName = (TextView) holder.infoPage.findViewById(R.id.nickname);

                for (int id : IDS_INTEREST)
                    holder.interests.add((TextView) holder.infoPage.findViewById(id));

                convertView.setTag(holder);
            } else {
                holder = (FriendsHolder) convertView.getTag();
            }

            switch (position) {
                // Merged page with 2 friends
                case 1:
                    holder.leftAvatar.setImageResource(friend1.getAvatar());
                    if (friend2 != null)
                        holder.rightAvatar.setImageResource(friend2.getAvatar());
                    break;
                default:
                    fillHolder(holder, position == 0 ? friend1 : friend2);
                    holder.infoPage.setTag(holder);
                    return holder.infoPage;
            }
            return convertView;
        }

        @Override
        public int getPagesCount() {
            return PAGES;
        }

        private void fillHolder(FriendsHolder holder, Friend friend) {
            if (friend == null)
                return;
            Iterator<TextView> iViews = holder.interests.iterator();
            Iterator<String> iInterests = friend.getInterests().iterator();
            while (iViews.hasNext() && iInterests.hasNext())
                iViews.next().setText(iInterests.next());
            holder.infoPage.setBackgroundColor(getResources().getColor(friend.getBackground()));
            holder.nickName.setText(friend.getNickname());
        }

        class FriendsHolder {
            ImageView leftAvatar;
            ImageView rightAvatar;
            View infoPage;

            List<TextView> interests = new ArrayList<>();
            TextView nickName;
        }
    }

 

运行效果:

 

 


你可能感兴趣的:(源码,框架,程序员,开源项目)