Skip to content

Commit 105ceb4

Browse files
author
Kishan Vaghela
committed
Merge branch 'branch_scroll'
2 parents c5fe6ef + 6728a6a commit 105ceb4

File tree

3 files changed

+58
-49
lines changed

3 files changed

+58
-49
lines changed
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
<RelativeLayout
2-
xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:app="http://schemas.android.com/apk/res-auto"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
65

76
<LinearLayout
8-
android:id="@+id/header"
9-
android:layout_width="match_parent"
10-
android:layout_height="wrap_content"
11-
android:orientation="vertical">
7+
android:id="@+id/header"
8+
android:layout_width="match_parent"
9+
android:layout_height="wrap_content"
10+
android:orientation="vertical">
1211

1312
<android.support.v7.widget.Toolbar
14-
android:id="@+id/toolbar"
15-
android:layout_width="match_parent"
16-
android:layout_height="wrap_content"
17-
android:minHeight="?attr/actionBarSize"
18-
android:background="?attr/colorPrimary"
19-
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
20-
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
13+
android:id="@+id/toolbar"
14+
android:layout_width="match_parent"
15+
android:layout_height="wrap_content"
16+
android:background="?attr/colorPrimary"
17+
android:minHeight="?attr/actionBarSize"
18+
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
19+
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
2120

2221
<com.nshmura.recyclertablayout.RecyclerTabLayout
23-
android:id="@+id/recycler_tab_layout"
24-
android:layout_width="match_parent"
25-
android:layout_height="@dimen/tab_height"
26-
android:background="@color/primary"
27-
android:theme="@style/RecyclerTabLayoutTheme.Basic"
28-
app:rtl_tabMaxWidth="@dimen/tab_width"
29-
app:rtl_tabSelectedTextColor="@android:color/white"/>
22+
android:id="@+id/recycler_tab_layout"
23+
android:layout_width="match_parent"
24+
android:layout_height="@dimen/tab_height"
25+
android:background="@color/primary"
26+
android:theme="@style/RecyclerTabLayoutTheme.Basic"
27+
app:rtl_scrollEnable="false"
28+
app:rtl_tabMaxWidth="@dimen/tab_width"
29+
app:rtl_tabSelectedTextColor="@android:color/white" />
3030
</LinearLayout>
3131

3232
<android.support.v4.view.ViewPager
33-
android:id="@+id/view_pager"
34-
android:layout_width="match_parent"
35-
android:layout_height="match_parent"
36-
android:layout_below="@id/header"/>
33+
android:id="@+id/view_pager"
34+
android:layout_width="match_parent"
35+
android:layout_height="match_parent"
36+
android:layout_below="@id/header" />
3737

3838
</RelativeLayout>

library/src/main/java/com/nshmura/recyclertablayout/RecyclerTabLayout.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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
}
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<declare-styleable name="rtl_RecyclerTabLayout">
4-
<attr name="rtl_tabIndicatorColor" format="color"/>
5-
<attr name="rtl_tabIndicatorHeight" format="dimension"/>
4+
<attr name="rtl_tabIndicatorColor" format="color" />
5+
<attr name="rtl_tabIndicatorHeight" format="dimension" />
66

7-
<attr name="rtl_tabBackground" format="reference"/>
7+
<attr name="rtl_tabBackground" format="reference" />
88

9-
<attr name="rtl_tabTextAppearance" format="reference"/>
10-
<attr name="rtl_tabSelectedTextColor" format="color"/>
9+
<attr name="rtl_tabTextAppearance" format="reference" />
10+
<attr name="rtl_tabSelectedTextColor" format="color" />
1111

12-
<attr name="rtl_tabMinWidth" format="dimension"/>
13-
<attr name="rtl_tabMaxWidth" format="dimension"/>
12+
<attr name="rtl_tabMinWidth" format="dimension" />
13+
<attr name="rtl_tabMaxWidth" format="dimension" />
1414

15-
<attr name="rtl_tabPaddingStart" format="dimension"/>
16-
<attr name="rtl_tabPaddingTop" format="dimension"/>
17-
<attr name="rtl_tabPaddingEnd" format="dimension"/>
18-
<attr name="rtl_tabPaddingBottom" format="dimension"/>
19-
<attr name="rtl_tabPadding" format="dimension"/>
15+
<attr name="rtl_tabPaddingStart" format="dimension" />
16+
<attr name="rtl_tabPaddingTop" format="dimension" />
17+
<attr name="rtl_tabPaddingEnd" format="dimension" />
18+
<attr name="rtl_tabPaddingBottom" format="dimension" />
19+
<attr name="rtl_tabPadding" format="dimension" />
20+
<attr name="rtl_scrollEnable" format="boolean" />
2021

2122
</declare-styleable>
2223
</resources>

0 commit comments

Comments
 (0)