Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pstsIndicatorMarginLeftRight #261

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9d75c31
Update attrs.xml
flyfly121 Aug 27, 2015
bb68332
Update PagerSlidingTabStrip.java
flyfly121 Aug 27, 2015
58c2886
Update attrs.xml
flyfly121 Jan 12, 2016
8e82c23
Update PagerSlidingTabStrip.java
flyfly121 Jan 12, 2016
1421fc1
Update README.md
flyfly121 Jan 12, 2016
6374626
Update README.md
flyfly121 Jan 12, 2016
38c2ab4
Update README.md
flyfly121 Jan 12, 2016
a8fd149
Update README.md
flyfly121 Jan 12, 2016
0f2a331
Update README.md
flyfly121 Jan 12, 2016
c21bb49
Update README.md
flyfly121 Jan 12, 2016
0e077fc
Update attrs.xml
flyfly121 Jan 12, 2016
4012f58
Update PagerSlidingTabStrip.java
flyfly121 Jan 12, 2016
de2ac0f
Update README.md
flyfly121 Jan 12, 2016
c5229c8
Update PagerSlidingTabStrip.java
flyfly121 Jan 12, 2016
d7ea7e7
Update PagerSlidingTabStrip.java
flyfly121 Jan 12, 2016
7af53f3
Update PagerSlidingTabStrip.java
flyfly121 Jan 12, 2016
42e8f06
Update README.md
flyfly121 Jan 12, 2016
22d7727
add a example image
Jan 12, 2016
e1368e3
Update README.md
flyfly121 Jan 12, 2016
bf0438a
add a small example image.
Jan 12, 2016
71310ad
Update README.md
flyfly121 Jan 12, 2016
469935c
Update README.md
flyfly121 Jan 12, 2016
9198731
Update README.md
flyfly121 Jan 12, 2016
556410f
Update README.md
flyfly121 Jan 12, 2016
45585b8
You need to read this
Jan 12, 2016
85fc167
Update README.md
flyfly121 Jan 12, 2016
dbf16e1
Update README.md
flyfly121 Jan 12, 2016
b15d5b5
gif
Jan 12, 2016
25a1e15
Merge
Jan 12, 2016
b37dc12
Update README.md
flyfly121 Jan 12, 2016
8d38ac0
Update PagerSlidingTabStrip.java
flyfly121 Jan 12, 2016
a022ffe
123
Aug 4, 2016
796b758
Update 新建文本文档.txt
flyfly121 Aug 4, 2016
a89b686
lalala
Aug 4, 2016
a474b54
Update 新建文本文档.txt
flyfly121 Aug 4, 2016
e8627af
git help text
Aug 4, 2016
9f78a87
;lskdjf
Aug 4, 2016
29295ac
del
Aug 4, 2016
24cc818
add a new file
Aug 4, 2016
6a01e3d
Update 新建文本文档.txt
flyfly121 Aug 4, 2016
b2b4d67
modify
Aug 4, 2016
c4fe178
asdf
Aug 4, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Android PagerSlidingTabStrip

## NEW UPDATE
```Java
public static final int INDICATOR_MODE_UNDERLINE = 0x1;
public static final int INDICATOR_MODE_BACKGROUND = 0x2;
```
* INDICATOR_MODE_UNDERLINE是原来的下划线的那种指示器
* INDICATOR_MODE_BACKGROUND是新增的圆角矩形背景的指示器

--
![](https://github.com/flyfly121/PagerSlidingTabStrip/blob/master/example.gif)

## HOW TO USE
```Java
tabs.setIndicatorMode(PagerSlidingTabStrip.INDICATOR_MODE_BACKGROUND);
```
====
原来下划线那种形式的指示器添加了几个新属性(请注意下面的图片,解释了几个关键词):
```xml
<attr name="pstsIndicatorMarginLeftRight" format="dimension" />
<attr name="pstsIndicatorAlignTabTextLeftRight" format="boolean" />
<attr name="pstsIndicatorOverflowTabText" format="dimension" />
```
* 第一个是指示器Indicator的左右边距
* 第二个是指示器Indicator的宽与TabText的宽相等,也就是alignLeft & alignRight
* 第三个是指示器Indicator的宽超出TabText的宽的距离

--
![](https://github.com/flyfly121/PagerSlidingTabStrip/blob/master/important_information.png)

====

Interactive paging indicator widget, compatible with the `ViewPager` from the
Android Support Library.

Expand Down
Binary file added example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions git_help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status

grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
tag Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
Binary file added important_information.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion library/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<attr name="pstsUnderlineColor" format="color" />
<attr name="pstsDividerColor" format="color" />
<attr name="pstsIndicatorHeight" format="dimension" />
<attr name="pstsIndicatorMarginLeftRight" format="dimension" />
<attr name="pstsIndicatorAlignTabTextLeftRight" format="boolean" />
<attr name="pstsIndicatorOverflowTabText" format="dimension" />
<attr name="pstsUnderlineHeight" format="dimension" />
<attr name="pstsDividerPadding" format="dimension" />
<attr name="pstsTabPaddingLeftRight" format="dimension" />
Expand All @@ -15,4 +18,4 @@
<attr name="pstsTextAllCaps" format="boolean" />
</declare-styleable>

</resources>
</resources>
80 changes: 75 additions & 5 deletions library/src/com/astuetz/PagerSlidingTabStrip.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ public interface IconTabProvider {
private static final int[] ATTRS = new int[] {
android.R.attr.textSize,
android.R.attr.textColor
};
};
// @formatter:on

public static final int INDICATOR_MODE_UNDERLINE = 0x1;
public static final int INDICATOR_MODE_BACKGROUND = 0x2;

private LinearLayout.LayoutParams defaultTabLayoutParams;
private LinearLayout.LayoutParams expandedTabLayoutParams;

Expand All @@ -72,7 +75,8 @@ public interface IconTabProvider {

private Paint rectPaint;
private Paint dividerPaint;

private RectF indicatorRectF;

private int indicatorColor = 0xFF666666;
private int underlineColor = 0x1A000000;
private int dividerColor = 0x1A000000;
Expand All @@ -82,6 +86,10 @@ public interface IconTabProvider {

private int scrollOffset = 52;
private int indicatorHeight = 8;
private int indicatorMarginLeftRight = 0;
private boolean indicatorAlignTabTextLeftRight = false;
private int indicatorOverflowTabText = 0;
private int indicatorBgPadding = 10;
private int underlineHeight = 2;
private int dividerPadding = 12;
private int tabPadding = 24;
Expand Down Expand Up @@ -121,11 +129,14 @@ public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {

scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
indicatorMarginLeftRight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorMarginLeftRight, dm);
indicatorOverflowTabText = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorOverflowTabText, dm);
underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);
indicatorBgPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorBgPadding, dm);

// get system attrs (android:textSize and android:textColor)

Expand All @@ -144,6 +155,9 @@ public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight);
indicatorMarginLeftRight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorMarginLeftRight, indicatorMarginLeftRight);
indicatorAlignTabTextLeftRight = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsIndicatorAlignTabTextLeftRight, indicatorAlignTabTextLeftRight);
indicatorOverflowTabText = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorOverflowTabText, indicatorOverflowTabText);
underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight);
dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding);
tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
Expand All @@ -162,6 +176,8 @@ public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
dividerPaint.setAntiAlias(true);
dividerPaint.setStrokeWidth(dividerWidth);

indicatorRectF = new RectF();

defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

Expand Down Expand Up @@ -333,9 +349,30 @@ protected void onDraw(Canvas canvas) {
lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
}

canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);


Paint p = ((TextView) currentTab).getPaint();
String text = ((TextView)currentTab).getText().toString();
text = textAllCaps ? text.toUpperCase(locale) : text;
float textLength = p.measureText(text);

if (indicatorOverflowTabText > 0 || indicatorAlignTabTextLeftRight) {
if (currentTab instanceof TextView) {
// minus the length of indicatorOverflowTabText
indicatorMarginLeftRight = (int) ((currentTab.getWidth() - textLength) / 2 - indicatorOverflowTabText);
}
}

// left and right changed
if (indicatorMode == INDICATOR_MODE_UNDERLINE) {
canvas.drawRect(lineLeft + indicatorMarginLeftRight, height - indicatorHeight, lineRight - indicatorMarginLeftRight, height, rectPaint);
} else if (indicatorMode == INDICATOR_MODE_BACKGROUND) {
indicatorRectF.left = lineLeft + (currentTab.getWidth() - textLength) / 2 - indicatorBgPadding;
indicatorRectF.top = indicatorHeight;
indicatorRectF.right = lineRight - (currentTab.getWidth() - textLength) / 2 + indicatorBgPadding;
indicatorRectF.bottom = height - indicatorHeight;
float r = (lineRight - 2 * indicatorHeight) / 2;
canvas.drawRoundRect(indicatorRectF, r, r, rectPaint);
}
// draw underline

rectPaint.setColor(underlineColor);
Expand Down Expand Up @@ -387,6 +424,14 @@ public void onPageSelected(int position) {

}

public int getIndicatorMode() {
return indicatorMode;
}

public void setIndicatorMode(int indicatorMode) {
this.indicatorMode = indicatorMode;
}

public void setIndicatorColor(int indicatorColor) {
this.indicatorColor = indicatorColor;
invalidate();
Expand All @@ -410,6 +455,31 @@ public int getIndicatorHeight() {
return indicatorHeight;
}

public int getIndicatorMarginLeftRight() {
return indicatorMarginLeftRight;
}

public void setIndicatorMarginLeftRight(int indicatorMarginLeftRight) {
this.indicatorMarginLeftRight = indicatorMarginLeftRight;
}

public boolean isIndicatorAlignTabTextLeftRight() {
return indicatorAlignTabTextLeftRight;
}

public void setIndicatorAlignTabTextLeftRight(
boolean indicatorAlignTabTextLeftRight) {
this.indicatorAlignTabTextLeftRight = indicatorAlignTabTextLeftRight;
}

public int getIndicatorBgPadding() {
return indicatorBgPadding;
}

public void setIndicatorBgPadding(int indicatorBgPadding) {
this.indicatorBgPadding = indicatorBgPadding;
}

public void setUnderlineColor(int underlineColor) {
this.underlineColor = underlineColor;
invalidate();
Expand Down
2 changes: 2 additions & 0 deletions 新建文本文档.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
����һ����
public static final main