Giter Site home page Giter Site logo

recyclertablayout's Introduction

RecyclerTabLayout

Android Arsenal

An efficient TabLayout library implemented with RecyclerView.

Features

  • Efficient when having many tabs
  • Easy setup with ViewPager (same as TabLayout of Android Design Support Library)
  • RTL layout support

UseCase

  • Many tabs layout
  • Infinite loop scrolling (imitated)

Demos

Years

Loop

Basic

Icon

Samples

Getting started

In your build.gradle:

repositories {
    jcenter()
}

dependencies {
   compile 'com.nshmura:recyclertablayout:1.5.0'
}

Define RecyclerTabLayout in xml layout with custom attributes.

<com.nshmura.recyclertablayout.RecyclerTabLayout
        android:id="@+id/recycler_tab_layout"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        rtl_tabIndicatorColor="?attr/colorAccent"
        rtl_tabIndicatorHeight="2dp"
        rtl_tabBackground="?attr/selectableItemBackground"
        rtl_tabTextAppearance="@android:style/TextAppearance.Small"
        rtl_tabSelectedTextColor="?android:textColorPrimary"
        rtl_tabMinWidth="72dp"
        rtl_tabMaxWidth="264dp"
        rtl_tabPaddingStart="12dp"
        rtl_tabPaddingTop="0dp"
        rtl_tabPaddingEnd="12dp"
        rtl_tabPaddingBottom="0dp"
        rtl_tabPadding="0dp"/>

Set up with the ViewPager.

ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
viewPager.setAdapter(adapter);

RecyclerTabLayout recyclerTabLayout = (RecyclerTabLayout) findViewById(R.id.recycler_tab_layout);
recyclerTabLayout.setUpWithViewPager(viewPager);

Or set up with ViewPager and Custom RecyclerView.Adapter that's extends RecyclerTabLayout.Adapter.

ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
viewPager.setAdapter(adapter);

RecyclerTabLayout recyclerTabLayout = (RecyclerTabLayout) findViewById(R.id.recycler_tab_layout);
recyclerTabLayout.setUpWithAdapter(new CustomRecyclerViewAdapter(viewPager));

Here's sample of custom RecyclerView adapter.

public class CustomRecyclerViewAdapter extends RecyclerTabLayout.Adapter<CustomRecyclerViewAdapter.ViewHolder> {

    public DemoCustomView01Adapter(ViewPager viewPager) {
        super(viewPager);
        ...
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        // Inflate your view.
        View view = ...;
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        // Bind data
        ...
        
        if (position == getCurrentIndicatorPosition()) {
            //Highlight view
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ...
        
        public ViewHolder(View itemView) {
            super(itemView);
        ...
        }
    }
}

Attributes

attr description
rtl_tabIndicatorColor Indicator color
rtl_tabIndicatorHeight Indicator height
rtl_tabBackground Background drawable of each tab
rtl_tabTextAppearance TextAppearence of each tab
rtl_tabSelectedTextColor Text color of selected tab
rtl_tabOnScreenLimit The number of OnScreen tabs. If this value is larger than 0, rtl_tabMinWidth and rtl_tabMaxWidth are ignored.
rtl_tabMinWidth Minimum width of each tab
rtl_tabMaxWidth Maximum width of each tab
rtl_tabPaddingStart The padding of the start edge of each tab
rtl_tabPaddingTop The padding of the top edge of each tab
rtl_tabPaddingEnd The padding of the end edge of each tab
rtl_tabPaddingBottom The padding of the bottom edge of each tab
rtl_tabPadding The padding of all four edges of each tab
rtl_scrollEnabled Sets whether tab scrolling is enabled

default attribute

Thanks

The demo app uses the following resources.

color-names by codebrainz
https://github.com/codebrainz/color-names

Material Design icons by Google
https://github.com/google/material-design-icons

License

Copyright (C) 2017 nshmura

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.

recyclertablayout's People

Contributors

cypressious avatar iodragon avatar nshmura avatar takuaraki 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  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  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  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

recyclertablayout's Issues

Any way to center tabs?

I have a RecyclerTabLayout with only two tabs and texts not too long. I'd like to know if it's possible to center-align tabs, since right now they appear left aligned

CrashHandler: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/internal/widget/TintManager;

06-29 10:47:50.354 23962-23962/cn.com.kpcq.xunjian.jinan E/CrashHandler: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/internal/widget/TintManager;
at com.nshmura.recyclertablayout.RecyclerTabLayout$DefaultAdapter.onCreateViewHolder(RecyclerTabLayout.java:479)
at com.nshmura.recyclertablayout.RecyclerTabLayout$DefaultAdapter.onCreateViewHolder(RecyclerTabLayout.java:435)

line 479

if (mTabBackgroundResId != 0) {
tabTextView.setBackgroundDrawable(
479 TintManager.getDrawable(tabTextView.getContext(), mTabBackgroundResId));
}

rtl support

hi, thanks for your great library

can you add rtl support to this library ?

everything is ok, but Indicator moves reverse .

about current position

I want to send tablayout's current position to recyclerview in recyclertablayout but instantiateItem doesn't give current position.
Best regards

1.5.0 problem with fragmentsstateadapter

The recent version doesnt work well with the FragmentStateAdapter.. it was working fine in 1.1.0 . Some thing has changed . Our app has infinite loop logic in place and is working with 1.1.0. When we upgrade to 1.5.0 ,No matter how you set the currentItem() the first tab always appears on the first position instead of being centered and wont display any fragment content. I checked the demo code and it is same as mine except the demo is presented with PageAdapter. Is there any one facing this issue or figured the root issue ?

Indicator disapears after setting cutom tabBackground

First of thanks for useful Widget!!!
I have a problem, after setting app:rtl_tabBackground="@color/darkRed" indicator disapears. Before setting tabBackground all works Perfectly.
Do i miss something in readme?

Any further development planned?

I don't know if it's possible, but I have some ideas. ;-)
How about to add badges to tablayout or make the tablayout/viewpager not swipeable,...

Tabs not scrolled on init on support library 23.3.0

If you set current pager item that is outside TabLayout (selectedView == null), tabs dont scroll to that item position. This happens when using 23.3.0 support library and only at view initialization. Once you move pager, tabs jump to the correct position.

Support Library 23.3.0 LinearLayoutManager has a new feature called setAutoMeasureEnabled which is default enabled. This seems to cause this issue on init.

The solution is to set it to false in the RecyclerTabLayout constructor when setting LinearLayoutManager.

       /.../
        mIndicatorPaint = new Paint();
        mLinearLayoutManager = new LinearLayoutManager(getContext());
        mLinearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        mLinearLayoutManager.setAutoMeasureEnabled(false);
        setLayoutManager(mLinearLayoutManager);
        setItemAnimator(null);
        /.../

android.view.InflateException: Binary XML file line #19: Binary XML file line #19

android.view.InflateException: Binary XML file line #19: Binary XML file line #19: Error inflating class com.nshmura.recyclertablayout.RecyclerTabLayout
Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class com.nshmura.recyclertablayout.RecyclerTabLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.hyphenate.chatuidemo.ui.PacketsFragment.onCreateView(PacketsFragment.java:50)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2343)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:794)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3221)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3171)
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:552)
at com.hyphenate.chatuidemo.ui.BaseActivity.onStart(BaseActivity.java:36)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1391)
at android.app.Activity.performStart(Activity.java:7157)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2937)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 2: TypedValue{t=0x2/d=0x7f03004d a=4}
at android.content.res.TypedArray.getColor(TypedArray.java:477)
at com.nshmura.recyclertablayout.RecyclerTabLayout.getAttributes(RecyclerTabLayout.java:101)
at com.nshmura.recyclertablayout.RecyclerTabLayout.(RecyclerTabLayout.java:85)
at com.nshmura.recyclertablayout.RecyclerTabLayout.(RecyclerTabLayout.java:78)

the line 19 is "<com.nshmura.recyclertablayout.RecyclerTabLayout"

4.4.4color invalid

On the android4.4.4 system, the default font color set on the style file is invalid

requestLayout() improperly called

I am getting this warning , may be you want to look at it

W/View: requestLayout() improperly called by com.nshmura.recyclertablayout.RecyclerTabLayout{10a88d34 VFED.... ......ID 30,0-1050,144 #7f0e0093 app:id/recycler_tab_layout} during layout: running second layout pass

Android SDK : 24.0.1

Lag when switching from last tab

I currently use the loop method to infinitely scroll through tabs. It all works fine when I switch between fragments when swiping the viewpager itself, however, when I switch from the last to the first tab or the last to the previous tab by clicking on the tabs in the RecyclerTabLayout, some lag occurs.

How to Change text color of unselected tabs

Hello, I'm using this infinite loop demo. And I want to change unselected tab text color. I know that there is an attribute called "rtl_tabSelectedTextColor". Is there something to achieve this?

Text Size

Hi. I have tried to change text size of each tab. How can I chance it?.

Here my code. I thought I can set it through "tabTextAppearance". But it did not affect :(

android:id="@+id/home_screen_recycler_tab_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/engly_light_purple"
app:rtl_tabIndicatorColor="@color/subtitle_dark_purple"
app:rtl_tabIndicatorHeight="50dp"
app:rtl_tabSelectedTextColor="@color/white"
app:rtl_tabTextAppearance="@dimen/home_screen_home_catagories"

Invalid indicator position

Sometimes when I change position of ViewPager I see that current tab at RecyclerTabLayout stay the same. I've figure out after some debugging where is problem.
See at method updateCurrentIndicatorPosition. This method don't change adapter's indicatorPosition if dx is 0. So RecyclerTabLayout's position and ViewPager's position do not match.

protected void updateCurrentIndicatorPosition(int position, float dx, float positionOffset) {
if (mAdapter == null) {
return;
}
int indicatorPosition = -1;
if (dx > 0 && positionOffset >= mPositionThreshold - POSITION_THRESHOLD_ALLOWABLE) {
indicatorPosition = position + 1;
} else if (dx < 0 && positionOffset <= 1 - mPositionThreshold + POSITION_THRESHOLD_ALLOWABLE) {
indicatorPosition = position;
}
if (indicatorPosition >= 0 && indicatorPosition != mAdapter.getCurrentIndicatorPosition()) {
mAdapter.setCurrentIndicatorPosition(indicatorPosition);
mAdapter.notifyDataSetChanged();
}
}

Was there any possible load image Picasso or Glide Recycler Tablayout ?

I have following the example of customview01 by using the this DemoCustomView01Activity.class
then in adapter DemoCustomView01Adapter which I used picasso to load image by
Picasso.with(context).load(item.getUrl()).into(holder.image); I think will load image into imageview.
But the result it was not..anybody can help me about this one please

tab多行

tab多行文本,怎么设置,字体大小不一样

Facing null object reference issue.

Attempt to invoke virtual method 'int gs.c()' on a null object reference
at com.nshmura.recyclertablayout.RecyclerTabLayout$DefaultAdapter.getItemCount(RecyclerTabLayout.java:544)

Please provide solution..

Swiping Left

Hi,

While swiping left page title color's looks wrong.

the demo download cannot work normal

because of your gradle build different and i don not know how to configure it ,
at last , i create new project with gradle denpendice and copy the demo code ...

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.