Giter Site home page Giter Site logo

sample's Introduction

android tablayout

有不足之地,欢迎指点!

可以设置图片,图片的位置 left/top/right/bottom 图片和文字的选择器,是否显示图片等功能,具体使用方法如下:

    <com.tablayoutlibrary.app.CommonTabLayout
            android:id="@id/common_tablayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal"
            android:padding="10dp"
            tl:tl_iconGravity="TOP"
            tl:tl_iconHeight="20dp"
            tl:tl_iconVisible="true"
            tl:tl_iconWidth="20dp"
            tl:tl_indicatorAnimEnable="true"
            tl:tl_indicatorColor="@color/colorPrimary"
            tl:tl_indicatorEnable="true"
            tl:tl_indicatorGravity="INDICATOR_TOP"
            tl:tl_indicatorMarginBottom="6dp"
            tl:tl_indicatorMarginTop="6dp"
            tl:tl_tabPadding="5dp"
            tl:tl_textSelectColor="@color/color_f39800"
            tl:tl_textUnSelectColor="@color/color_545454"
            tl:tl_textsize="12sp"/>

  在页面中设置,可以关联viewpager

      ArrayList<TabEntity> list = new ArrayList<>();
            for (int i = 0; i < TITLE.length; i++) {
                TabEntity tabEntity = new TabEntity();
                tabEntity.tabTitle = TITLE[i];
                tabEntity.selectedIcon = mIconSelectIds[i];
                tabEntity.unSelectedIcon = mIconUnselectIds[i];
                list.add(tabEntity);
            }
            tablayout.setTabData(list);
            tablayout.setOnSelectorListener(new CommonTabLayout.OnSelectorListener() {
                @Override
                public void onSeletor(int position) {
    //                viewPager.setCurrentItem(position);
                }
            });

    ArrayList<BaseFragment> fragments = new ArrayList<>();
    fragments.add(BaseFragment.newInstance(this, OneFragment.class));
    fragments.add(BaseFragment.newInstance(this, TwoFragment.class));
    fragments.add(BaseFragment.newInstance(this, NewsFragment.class));
    fragments.add(BaseFragment.newInstance(this, FourFragment.class));
    viewPager.setAdapter(new MainPagerAdapter(getFragmentManager(), fragments));
    tablayout.setUpWithViewPager(viewPager);

自定义属性

    <!-- indicator -->
    <attr name="tl_indicatorColor" format="color"/>
    <attr name="tl_indicatorHeight" format="dimension"/>
    <attr name="tl_indicatorWidth" format="reference"/>
    <attr name="tl_indicatorMarginLeft" format="reference"/>
    <attr name="tl_indicatorMarginTop" format="dimension"/>
    <attr name="tl_indicatorMarginRight" format="dimension"/>
    <attr name="tl_indicatorMarginBottom" format="dimension"/>
    <attr name="tl_indicatorGravity">
        <flag name="INDICATOR_LEFT" value="0x1001"/>
        <flag name="INDICATOR_TOP" value="0x1002"/>
        <flag name="INDICATOR_RIGHT" value="0x1003"/>
        <flag name="INDICATOR_BOTTOM" value="0x1004"/>
    </attr>
    <attr name="tl_indicatorEnable" format="boolean"/>
    <attr name="tl_indicatorAnimEnable" format="boolean"/>

sample's People

Contributors

weishl110 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.