Skip to content

Update the textwidth to contentwidth #213

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import java.util.ArrayList;
import java.util.Collections;

/** 滑动TabLayout,对于ViewPager的依赖性强 */
/**
* 滑动TabLayout,对于ViewPager的依赖性强
*/
public class SlidingTabLayout extends HorizontalScrollView implements ViewPager.OnPageChangeListener {
private Context mContext;
private ViewPager mViewPager;
Expand All @@ -42,9 +44,13 @@ public class SlidingTabLayout extends HorizontalScrollView implements ViewPager.
private int mCurrentTab;
private float mCurrentPositionOffset;
private int mTabCount;
/** 用于绘制显示器 */
/**
* 用于绘制显示器
*/
private Rect mIndicatorRect = new Rect();
/** 用于实现滚动居中 */
/**
* 用于实现滚动居中
*/
private Rect mTabRect = new Rect();
private GradientDrawable mIndicatorDrawable = new GradientDrawable();

Expand All @@ -61,7 +67,9 @@ public class SlidingTabLayout extends HorizontalScrollView implements ViewPager.
private boolean mTabSpaceEqual;
private float mTabWidth;

/** indicator */
/**
* indicator
*/
private int mIndicatorColor;
private float mIndicatorHeight;
private float mIndicatorWidth;
Expand All @@ -73,17 +81,23 @@ public class SlidingTabLayout extends HorizontalScrollView implements ViewPager.
private int mIndicatorGravity;
private boolean mIndicatorWidthEqualTitle;

/** underline */
/**
* underline
*/
private int mUnderlineColor;
private float mUnderlineHeight;
private int mUnderlineGravity;

/** divider */
/**
* divider
*/
private int mDividerColor;
private float mDividerWidth;
private float mDividerPadding;

/** title */
/**
* title
*/
private static final int TEXT_BOLD_NONE = 0;
private static final int TEXT_BOLD_WHEN_SELECT = 1;
private static final int TEXT_BOLD_BOTH = 2;
Expand Down Expand Up @@ -168,7 +182,9 @@ private void obtainAttributes(Context context, AttributeSet attrs) {
ta.recycle();
}

/** 关联ViewPager */
/**
* 关联ViewPager
*/
public void setViewPager(ViewPager vp) {
if (vp == null || vp.getAdapter() == null) {
throw new IllegalStateException("ViewPager or ViewPager adapter can not be NULL !");
Expand All @@ -181,7 +197,9 @@ public void setViewPager(ViewPager vp) {
notifyDataSetChanged();
}

/** 关联ViewPager,用于不想在ViewPager适配器中设置titles数据的情况 */
/**
* 关联ViewPager,用于不想在ViewPager适配器中设置titles数据的情况
*/
public void setViewPager(ViewPager vp, String[] titles) {
if (vp == null || vp.getAdapter() == null) {
throw new IllegalStateException("ViewPager or ViewPager adapter can not be NULL !");
Expand All @@ -204,7 +222,9 @@ public void setViewPager(ViewPager vp, String[] titles) {
notifyDataSetChanged();
}

/** 关联ViewPager,用于连适配器都不想自己实例化的情况 */
/**
* 关联ViewPager,用于连适配器都不想自己实例化的情况
*/
public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, ArrayList<Fragment> fragments) {
if (vp == null) {
throw new IllegalStateException("ViewPager can not be NULL !");
Expand All @@ -222,7 +242,9 @@ public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, Arr
notifyDataSetChanged();
}

/** 更新数据 */
/**
* 更新数据
*/
public void notifyDataSetChanged() {
mTabsContainer.removeAllViews();
this.mTabCount = mTitles == null ? mViewPager.getAdapter().getCount() : mTitles.size();
Expand All @@ -249,7 +271,9 @@ public void addNewTab(String title) {
updateTabStyles();
}

/** 创建并添加tab */
/**
* 创建并添加tab
*/
private void addTab(final int position, String title, View tabView) {
TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
if (tv_tab_title != null) {
Expand Down Expand Up @@ -334,7 +358,9 @@ public void onPageSelected(int position) {
public void onPageScrollStateChanged(int state) {
}

/** HorizontalScrollView滚到当前tab,并且居中显示 */
/**
* HorizontalScrollView滚到当前tab,并且居中显示
*/
private void scrollToCurrentTab() {
if (mTabCount <= 0) {
return;
Expand Down Expand Up @@ -387,8 +413,8 @@ private void calcIndicatorRect() {
if (mIndicatorStyle == STYLE_NORMAL && mIndicatorWidthEqualTitle) {
TextView tab_title = (TextView) currentTabView.findViewById(R.id.tv_tab_title);
mTextPaint.setTextSize(mTextsize);
float textWidth = mTextPaint.measureText(tab_title.getText().toString());
margin = (right - left - textWidth) / 2;
float contentWidth = tab_title.getMeasuredWidth() - tab_title.getPaddingLeft() - tab_title.getPaddingRight();
margin = (right - left - contentWidth) / 2;
}

if (this.mCurrentTab < mTabCount - 1) {
Expand Down Expand Up @@ -799,7 +825,9 @@ public void showDot(int position) {
showMsg(position, 0);
}

/** 隐藏未读消息 */
/**
* 隐藏未读消息
*/
public void hideMsg(int position) {
if (position >= mTabCount) {
position = mTabCount - 1;
Expand All @@ -812,7 +840,9 @@ public void hideMsg(int position) {
}
}

/** 设置未读消息偏移,原点为文字的右上角.当控件高度固定,消息提示位置易控制,显示效果佳 */
/**
* 设置未读消息偏移,原点为文字的右上角.当控件高度固定,消息提示位置易控制,显示效果佳
*/
public void setMsgMargin(int position, float leftPadding, float bottomPadding) {
if (position >= mTabCount) {
position = mTabCount - 1;
Expand All @@ -831,7 +861,9 @@ public void setMsgMargin(int position, float leftPadding, float bottomPadding) {
}
}

/** 当前类只提供了少许设置未读消息属性的方法,可以通过该方法获取MsgView对象从而各种设置 */
/**
* 当前类只提供了少许设置未读消息属性的方法,可以通过该方法获取MsgView对象从而各种设置
*/
public MsgView getMsgView(int position) {
if (position >= mTabCount) {
position = mTabCount - 1;
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.3'
// classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
// classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.2'
// NOTE: Do not place your application dependencies here; they belong
Expand Down
19 changes: 9 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

## Project-wide Gradle settings.
#
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true
#Fri Aug 25 15:19:52 CST 2017
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=6153
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Oct 10 13:13:42 CST 2015
#Fri Aug 25 15:20:13 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip