分享好友 移动开发首页 频道列表

一款强大的 Android 底部导航

Android开发  2016-11-22 17:200

:blush: JPTabBar :blush:

阅读中文文档请点击这里

ScreenShots:

Main functions and features:

  • More Animation effects of multiple Tab switching

  • Implements the effect of the middle button of the bottom navigation

  • Implements the kind of WeChat sliding navigation of the bottom gradient effect, with the change of the sliding distance

  • Implements the red mark on the TabBar, and can drag

  • The powerful BadgeView function, intelligent judgment digital hiding and cross-border display, two display modes。

  • Provide listening to the click event, middle click and badge is dragged away the interface

  • Reference annotation method, construction TabBarItem

Usage:

1.Introducing Gradle dependency

repositories {
        jcenter()
    }

    dependencies{
        compile 'com.jpeng:JPTabBar:1.1.2'
    }

2.Add JPTabBar to your main interface layout

<com.jpeng.jptabbar.JPTabBar
        android:id="@+id/tabbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        jp:TabHeight="56dp"
        jp:BadgeDraggable="true"
        jp:TabAnimate="Jump"
        jp:BadgePadding="4dp"
        jp:BadgeMargin="5dp"
        jp:BadgeTextSize="10dp"
        />

3.In your main interface using an array of variables to declare an array of variables, the internal reflection to generate TabItem, attention is: Titles and NorIcons are required, the length of each array should be consistent

@Titles
    private static final String[] mTitles = {"页面一","页面二","页面三","页面四"};

    @SeleIcons
    private static final int[] mSeleIcons = {R.mipmap.tab1_selected,R.mipmap.tab2_selected,R.mipmap.tab3_selected,R.mipmap.tab4_selected};

    @NorIcons
    private static final int[] mNormalIcons = {R.mipmap.tab1_normal, R.mipmap.tab2_normal, R.mipmap.tab3_normal, R.mipmap.tab4_normal};

4.After above, the layout of the TabBar basically has been built. If you want to achieve Wechat kind of gradual change as there are automatically ViewPager to change the function of the page, only in the oncreate Activity method, adding a line of code:

//The parameters must be extends ViewPager
    mTabbar.setContainer(mPager);

5.The project has provided many animation,If you want to Custom your Animation,You can setCustomAnimate,Duclipte of examples:

mTabbar.setCustomAnimate(new Animatable() {
                /**
                 * When you Tab Pager,The method will be called
                 * @param target IconView in the iconview
                 * @param Duration your animation time
                 */
                @Override
                public void playAnimate(View target, int Duration) {
                    ViewHelper.setPivotX(target,target.getLayoutParams().width/2);
                    ViewHelper.setPivotY(target,target.getLayoutParams().height/2);

                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(
                            ObjectAnimator.ofFloat(target,"scaleX",0.2f,1f).setDuration(Duration),
                            ObjectAnimator.ofFloat(target,"scaleY",0.2f,1f).setDuration(Duration),
                            ObjectAnimator.ofFloat(target,"alpha",0.3f,1f).setDuration(Duration)
                    );

                    set.start();
                }

                /**
                 * The explain of the Method
                 * When you touch in the ViewPager by User,The method will be called back
                 * @param target The same in top
                 * @param offset Range value 0f-1f
                 */
                @Override
                public void onPageAnimate(View target, float offset) {
                    ViewHelper.setScaleX(target,1+offset*0.2f);
                    ViewHelper.setScaleY(target,1+offset*0.2f);
                }

                /**
                 * return true can make onPageAnimate method called
                 * @return
                 */
                @Override
                public boolean isNeedPageAnimate() {
                    return true;
                }
            });

Method and node description:

The Main Method Of JPTabBar:

/**
     * Set custom Tab toggle animation
     */
    public void setCustomAnimate(Animatable customAnimate);


     /**
     * Show the BadgeView With Text
     */
    public void ShowBadge(int position,String text);

    /**
     * Hide the OVAL Badge
     */
    public void HideBadge(int position);

    /**
     * Switch Tab page, whether with animation
     */
    public void setSelectTab(int index, boolean animated);

    /**
     * Set the Observer of the Click Tab Event
     */
    public void setTabListener(OnTabSelectListener listener);

    /**
     * set the CallBack of the Badge Dragging Dismiss
     */
    public void setDismissListener(BadgeDismissListener listener);

Attribute Explain:

Attribute Name Attribute Explain Parameter Type Default Value
TabHeight TabBar height, will cover the settings of layout_height dimension 56dp
TabNormalColor Font and icon of the normal color color 0xffAEAEAE(Gray)
TabSelectColor Font and icon of the selected color color 0xff59D9B9(Cyan)
TabTextSize the textsize of the bottom text dimension 14sp
TabIconSize the icon size of the tab dimension 24dp
TabIconFilter Set the icon change by the font color boolean true
TabMargin Set the icon distance above and below the distance from the text dimension 8dp
TabSelectBg Set the TabItem Selected bg color transparent
TabAnimate The animate type of the Tab Switch enum Scale
TabMiddleIcon The middle Icon of the tab drawable
BadgeColor The background of the badgeView color #f00(RED)
BadgeDraggable Can drag on the badge touched by user boolean false
BadgePadding The background expansion distance of the badge dimension 4dp
BadgeTextSize The textSize of the Badge dimension 11dp
BadgeMargin The badge right margin in the TabBar dimension 9dp

Matters needing attention

1.If you have given setContainer TabBar, do not setOnPageChangeListener to ViewPager

/**
    *If you already have the TabBar set up the container, 
    *and then call this method,
    *the kind of WeChat that drag the gradient effect and automatically switch the page will be invalid
    *If you want to listen to the page to change the event, you can use the TabListener
   */
  mPager.setOnPageChangeListener(this);

2.If you want to achieve the middle of the button, you must set the android:clipChildren= "false" to the parent node at the top of the main interface, otherwise it will be covered.

<?xml version="1.0" encoding="utf-8"?>
  <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:jp="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    android:gravity="bottom"
    android:orientation="vertical"
    >

Update Log

V1.0.4

  • Reverse the BadgePosition show error
  • Reverse the background covered by the TabItem Bg
  • Reverse the Default value error

V1.0.5

  • Reverse the BadgeView cannot move to LeftTop
  • Titles annotaion support int
  • Remove BadgeModes annotation,Enhance the flexibility of the use of badges,Update the TabBar method
  • Add the TabSelectBg attribute,used to set the selected item bg

V1.1.0

  • Reverse the Rending problem in the XML
  • Reverse the BUG of CLick Tab Event CallBack twice.
  • Add the OnPageAnimate Method in interface,Enhance the flexibility of animation

V1.1.2

  • Add the Bouncing of the Animation
  • Reverse don't click when have no Pager in the Adapter

Hope

If you think this project is fast and useful, help, don't forget to click on the upper right corner of the star, because I want to challenge the BAT school recruit in the next year。

The world's strong programmer code process will inevitably appear BUG, if the user found BUG, you can contact me or directly issue, thank you!

About Me

A college student, is still in the study of various techniques...

QQ:83508440

E-mail: 83508440@qq.com

License

Copyright 2016 [JPeng]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

查看更多关于【Android开发】的文章

展开全文
相关推荐
反对 0
举报 0
评论 0
图文资讯
热门推荐
优选好物
更多热点专题
更多推荐文章
Supporting Multiple Screens
术语和概念Screen size 屏幕尺寸又称「屏幕大小」,是屏幕对角线的物理尺寸。单位英寸 inch,比如 Samsung Note4 是 5.7 英寸。Resolution 屏幕分辨率屏幕纵横方向上物理像素的总数,比如 Samsung Note4 是 2560x1440,表示纵向有 2560 个像素,横向有 1440

0评论2017-02-05363

Android插件化(4):OpenAtlasの插件的卸载与更新
如果看过我的前两篇博客Android插件化(2):OpenAtlas插件安装过程分析和Android插件化(3):OpenAtlas的插件重建以及使用时安装,就知道在插件的安装过程中OpenAtlas做了哪些事,那么插件的卸载就只需要把持久化和内存中的内容移除即可。1.插件的卸载插件卸载的

0评论2017-02-05229

个人简历
吴朝晖/男/1993.1本科/南京师范大学中北学院信息系工作年限:1年以内技术博客:wuzhaohui026.github.ioGitHub:https://github.com/wuzhaohui026期望职位:Android开发(初级Android工程师)期望薪资:税前月薪5.5k~7k期望城市:常州工作经历常州慧展信息科技有

0评论2017-02-05126

Android插件化(五):OpenAtlasの四大组件的Hack
引言到目前为止,我们已经分析了OpenAtlas中插件的安装,卸载,更新,以及安装好插件之后组件类的加载过程,但是对于这些是如何引发的还不知道,比如,在宿主的一个Activit中调用startActivity()跳转到插件中的一个Activity,如何判断这个Activity在的插件是否

0评论2017-02-0598

更多推荐