示例#1
0
        //Dessine La bande
        protected override void OnDraw(Canvas canvas)                                                                                  //Canvas permet au "view" de se dessiner
        {
            int height          = Height;                                                                                              //Height : Retourne la taille de la vue (View)
            int tabCount        = ChildCount;                                                                                          //ChildCount : Retourne le nombre de fils dans le groupe (ViewGroup)
            int dividerHeightPx = (int)(Math.Min(Math.Max(0f, mDividerHeight), 1f) * height);                                          //Fixe la taille de la barre séparant les différents onglets

            SlidingTabScrollView.TabColorizer tabColorizer = mCustomTabColorizer != null ? mCustomTabColorizer : mDefaultTabColorizer; //On vérifie si le mCustomTabColorizer est null, si il ne l'est pas cela signifie que l'utilisateur utilise son propre mCustomTabColorizer autrement on utilise notre mDefaultTabColorizer

            //Indicateur
            if (tabCount > 0)                                       //Sinon cela signifie qu'il n'y a pas d'onglet
            {
                View SelectedTitle = GetChildAt(mSelectedPosition); //On récupère le view à la position sélectionnée
                int  left          = SelectedTitle.Left;            //Position gauche de ce view
                int  right         = SelectedTitle.Right;           //Position droite de ce view
                int  color         = tabColorizer.GetIndicatorColor(mSelectedPosition);

                if (mSelectionOffSet > 0f && mSelectedPosition < (tabCount - 1)) //Si le mSelectionOffSet est égal à 0 cela signifie que le glissement est finis
                {
                    //Change la couleur de l'indicateur
                    int nextColor = tabColorizer.GetIndicatorColor(mSelectedPosition + 1);
                    if (color != nextColor)
                    {
                        color = blendColor(nextColor, color, mSelectionOffSet);
                    }
                    //Change de view et actualise gauche et droite
                    View nextTitle = GetChildAt(mSelectedPosition + 1);
                    left  = (int)(mSelectionOffSet * nextTitle.Left + (1.0f - mSelectionOffSet) * left);
                    right = (int)(mSelectionOffSet * nextTitle.Right + (1.0f - mSelectionOffSet) * right);
                }

                mSelectedIndicatorPaint.Color = GetColorFromInteger(color);

                canvas.DrawRect(left, height - mSelectedIndicatorThickness, right, height, mSelectedIndicatorPaint);

                //Créer la barre séparant les différents onglet
                int separatorTop = (height - dividerHeightPx) / 2;
                for (int i = 0; i < ChildCount; i++)
                {
                    View child = GetChildAt(i);
                    mDividerPaint.Color = GetColorFromInteger(tabColorizer.GetDividerColor(i));
                    canvas.DrawLine(child.Right, separatorTop, child.Right, separatorTop + dividerHeightPx, mDividerPaint);
                }
                //Dessine la bordure de la bande
                canvas.DrawRect(0, height - mBottomBorderThickness, Width, height, mBottomBorderPaint);
            }
        }
示例#2
0
        protected override void OnDraw(Canvas canvas)
        {
            int height          = Height;
            int tabCount        = ChildCount;
            int dividerHeightPx = (int)(Math.Min(Math.Max(0f, mDividerHeight), 1f) * height);

            SlidingTabScrollView.TabColorizer tabColorizer = mCustomTabColorizer != null ? mCustomTabColorizer : mDefaultTabColorizer;

            //thick colored underline below the current selection
            if (tabCount > 0)
            {
                View selectedTitle = GetChildAt(mSelectedPosition);
                int  left          = selectedTitle.Left;
                int  right         = selectedTitle.Right;
                int  color         = tabColorizer.GetIndicatorColor(mSelectedPosition);

                if (mSelectionOffset > 0f && mSelectedPosition < (tabCount - 1))
                {
                    int nextColor = tabColorizer.GetIndicatorColor(mSelectedPosition + 1);
                    if (color != nextColor)
                    {
                        color = blendColor(nextColor, color, mSelectionOffset);
                    }

                    View nextTitle = GetChildAt(mSelectedPosition + 1);
                    left  = (int)(mSelectionOffset * nextTitle.Left + (1.0f - mSelectionOffset) * left);
                    right = (int)(mSelectionOffset * nextTitle.Right + (1.0f - mSelectionOffset) * right);
                }


                mSelectedIndicatorPaint.Color = GetColorFromInteger(color);

                canvas.DrawRect(left, height - mSelectedIndicatorThickness, right, height, mSelectedIndicatorPaint);

                //create vertical dividers between tabs
                int separatorTop = (height * dividerHeightPx) / 2;
                for (int i = 0; i < ChildCount; i++)
                {
                    View child = GetChildAt(i);
                    mDividerPaint.Color = GetColorFromInteger(tabColorizer.GetDividerColor(i));
                    canvas.DrawLine(child.Right, separatorTop, child.Right, separatorTop + dividerHeightPx, mDividerPaint);
                }

                canvas.DrawRect(0, height - mBottomBorderThickness, Width, height, mBottomBorderPaint);
            }
        }
示例#3
0
        protected override void OnDraw(Canvas canvas)
        {
            int height          = Height;
            int tabCount        = ChildCount;
            int dividerHeightPx = (int)(Math.Min(Math.Max(0f, mDividerHeight), 1f) * height);

            SlidingTabScrollView.TabColorizer tabColorizer = mCustomTabColorizer != null ? mCustomTabColorizer : mDefaultTabColorizer;
            //Grube podkreślenie pod obecnym fragmentem
            if (tabCount > 0)
            {
                View selectedTitle = GetChildAt(mSelectedPosition);
                int  left          = selectedTitle.Left;
                int  right         = selectedTitle.Right;
                int  color         = tabColorizer.GetIndicatorColor(mSelectedPosition);

                if (mSelectionOffset > 0f && mSelectedPosition < (tabCount - 1))
                {
                    int nextColor = tabColorizer.GetIndicatorColor(mSelectedPosition + 1);
                    if (color != nextColor)
                    {
                        color = blendColor(nextColor, color, mSelectionOffset);
                    }

                    View nextTitle = GetChildAt(mSelectedPosition + 1);
                    left  = (int)(mSelectionOffset * nextTitle.Left + (1.0f - mSelectionOffset) * left);
                    right = (int)(mSelectionOffset * nextTitle.Right + (1.0f - mSelectionOffset) * right);
                }

                mSelectedIndicatorPaint.Color = GetColorFromInteger(color);
                canvas.DrawRect(left, height - mSelectedIndicatorThickness, right, height, mSelectedIndicatorPaint);

                //Tworzenie pionowego rozdzielacza między kartami
                int separatorTop = (height - dividerHeightPx) / 2;
                for (int i = 0; i < ChildCount; i++)
                {
                    View child = GetChildAt(i);
                    mDividerPaint.Color = GetColorFromInteger(tabColorizer.GetDividerColor(i));
                    canvas.DrawLine(child.Right, separatorTop, child.Right, separatorTop + dividerHeightPx, mDividerPaint);
                }
                canvas.DrawRect(0, height - mBottomBorderThickness, Width, height, mBottomBorderPaint);
            }
        }