11/**
22 * Copyright (C) 2015 nshmura
33 * Copyright (C) 2015 The Android Open Source Project
4- *
4+ * <p/>
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
77 * You may obtain a copy of the License at
8- *
8+ * <p/>
99 * http://www.apache.org/licenses/LICENSE-2.0
10- *
10+ * <p/>
1111 * Unless required by applicable law or agreed to in writing, software
1212 * distributed under the License is distributed on an "AS IS" BASIS,
1313 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -66,6 +66,7 @@ public class RecyclerTabLayout extends RecyclerView {
6666 protected float mOldPositionOffset ;
6767 protected float mPositionThreshold ;
6868 protected boolean mRequestScrollToTab ;
69+ protected boolean canScroll ;
6970
7071 public RecyclerTabLayout (Context context ) {
7172 this (context , null );
@@ -78,13 +79,21 @@ public RecyclerTabLayout(Context context, AttributeSet attrs) {
7879 public RecyclerTabLayout (Context context , AttributeSet attrs , int defStyle ) {
7980 super (context , attrs , defStyle );
8081 setWillNotDraw (false );
81-
8282 mIndicatorPaint = new Paint ();
83- mLinearLayoutManager = new LinearLayoutManager (getContext ());
83+ getAttributes (context , attrs , defStyle );
84+ mLinearLayoutManager = new LinearLayoutManager (getContext ()) {
85+ @ Override
86+ public boolean canScrollHorizontally () {
87+ return canScroll ;
88+ }
89+ };
8490 mLinearLayoutManager .setOrientation (LinearLayoutManager .HORIZONTAL );
8591 setLayoutManager (mLinearLayoutManager );
8692 setItemAnimator (null );
93+ mPositionThreshold = DEFAULT_POSITION_THRESHOLD ;
94+ }
8795
96+ private void getAttributes (Context context , AttributeSet attrs , int defStyle ) {
8897 TypedArray a = context .obtainStyledAttributes (attrs , R .styleable .rtl_RecyclerTabLayout ,
8998 defStyle , R .style .rtl_RecyclerTabLayout );
9099 setIndicatorColor (a .getColor (R .styleable
@@ -118,9 +127,8 @@ public RecyclerTabLayout(Context context, AttributeSet attrs, int defStyle) {
118127 R .styleable .rtl_RecyclerTabLayout_rtl_tabMaxWidth , 0 );
119128 mTabBackgroundResId = a
120129 .getResourceId (R .styleable .rtl_RecyclerTabLayout_rtl_tabBackground , 0 );
130+ canScroll = a .getBoolean (R .styleable .rtl_RecyclerTabLayout_rtl_scrollEnable , true );
121131 a .recycle ();
122-
123- mPositionThreshold = DEFAULT_POSITION_THRESHOLD ;
124132 }
125133
126134 @ Override
@@ -339,7 +347,7 @@ protected static class RecyclerOnScrollListener extends OnScrollListener {
339347 protected LinearLayoutManager mLinearLayoutManager ;
340348
341349 public RecyclerOnScrollListener (RecyclerTabLayout recyclerTabLayout ,
342- LinearLayoutManager linearLayoutManager ) {
350+ LinearLayoutManager linearLayoutManager ) {
343351 mRecyclerTabLayout = recyclerTabLayout ;
344352 mLinearLayoutManager = linearLayoutManager ;
345353 }
@@ -510,7 +518,7 @@ public int getItemCount() {
510518 }
511519
512520 public void setTabPadding (int tabPaddingStart , int tabPaddingTop , int tabPaddingEnd ,
513- int tabPaddingBottom ) {
521+ int tabPaddingBottom ) {
514522 mTabPaddingStart = tabPaddingStart ;
515523 mTabPaddingTop = tabPaddingTop ;
516524 mTabPaddingEnd = tabPaddingEnd ;
@@ -522,7 +530,7 @@ public void setTabTextAppearance(int tabTextAppearance) {
522530 }
523531
524532 public void setTabSelectedTextColor (boolean tabSelectedTextColorSet ,
525- int tabSelectedTextColor ) {
533+ int tabSelectedTextColor ) {
526534 mTabSelectedTextColorSet = tabSelectedTextColorSet ;
527535 mTabSelectedTextColor = tabSelectedTextColor ;
528536 }
0 commit comments