Code Monkey home page Code Monkey logo

tabviewpager's Introduction

TabViewPager

Download

TabViewPager,通过简单的接口实现ViewPager,Head,TabLayout组合展示

Demo

Compile

Download

compile 'com.goyourfly:tabviewpager:latestVersion'

Usage

xml
<com.goyourfly.tabviewpager.TabViewPager
        android:id="@+id/tabViewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
code
  • 1.定义Fragment
/** 
 * 自定义一个Fragment 继承自 BaseTabViewPagerFragment
 * 你可以在这个Fragment中加载数据
 */
class MyFragment() : BaseTabViewPagerFragment() {
	// 重写这个唯一的抽象方法,返回RecyclerView
    override fun getRecyclerView(): RecyclerView? {
        return recyclerView
    }
    ...
}
  • 2.定义ViewPager的Adapter
// 自定义ViewPagerAdapter必须继承BaseTabViewPagerAdapter
class MyViewPagerAdapter(fm: FragmentManager)
    : TabViewPager.BaseTabViewPagerAdapter(fm) {
    // 要显示的Tab
    val tabs = arrayOf("Tab1", "Tab2", "Tab3", "Tab4")
    override fun getItem(position: Int): BaseTabViewPagerFragment {
    	// 返回上面定义的Fragment
        return MyFragment()
    }

    override fun getCount(): Int {
        return tabs.size
    }

    override fun getPageTitle(position: Int): CharSequence {
        return tabs[position]
    }
}
  • 3.最后一步,初始化TabViewPager
// 加载头布局
val header = View.inflate(this, R.layout.layout_header, null)
// 初始化TabViewPager
TabViewPager.Builder
        .with(tabViewPager)
        .header(header)
        .parallax(true)
        .dispatchTouch(true) // 一般不需要打开,如果Header中有横向滑动的View并且有事件冲突时打开
        .adapter(MyViewPagerAdapter(FragmentManager))// 绑定Adapter
        .build()

tabviewpager's People

Contributors

goyourfly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tabviewpager's Issues

Issue with multiple fragments

Hello,

thank you for your library and your work :),
but there is an issue :

  1. i have a header, a (tablayout and multiple fragment with recyclerview) -> tabviewpager
  2. i scroll the first fragment until middle of header

capture d ecran 2017-12-04 a 21 46 05

3) i press the second tab of tablayout, the second fragment appears 4) i scroll the second fragment 5) i press again first tab to get first fragment, but the recyclerview position is at the beginning position under the tablayout

capture d ecran 2017-12-04 a 21 44 44

Thanks and Regards,
Darcheville

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.