Skip to content

Commit

Permalink
new added tablayout
Browse files Browse the repository at this point in the history
  • Loading branch information
H07000223 committed Dec 8, 2015
1 parent b3a84c6 commit 4cb128c
Show file tree
Hide file tree
Showing 9 changed files with 1,016 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.util.AttributeSet;
import android.util.Log;
Expand Down Expand Up @@ -73,12 +74,12 @@ public class CommonTabLayout extends FrameLayout implements ValueAnimator.Animat
private long indicatorAnimDuration;
private boolean indicatorAnimEnable;
private boolean indicatorBounceEnable;
private float indicatorGravity;
private int indicatorGravity;

/** underline */
private int underlineColor;
private float underlineHeight;
private float underlineGravity;
private int underlineGravity;

/** divider */
private int dividerColor;
Expand Down Expand Up @@ -148,7 +149,7 @@ private void obtainAttributes(Context context, AttributeSet attrs) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CommonTabLayout);

indicatorStyle = ta.getInt(R.styleable.CommonTabLayout_tl_indicator_style, 0);
indicatorColor = ta.getColor(R.styleable.CommonTabLayout_tl_indicator_color, Color.parseColor(indicatorStyle == STYLE_BLOCK ? "#4B6A87" : "#ffffff"));
indicatorColor = ta.getColor(R.styleable.CommonTabLayout_tl_indicator_color, Color.parseColor(indicatorStyle == STYLE_BLOCK ? "#4B6A87" : "#ffffff"));
indicatorHeight = ta.getDimension(R.styleable.CommonTabLayout_tl_indicator_height,
dp2px(indicatorStyle == STYLE_TRIANGLE ? 4 : (indicatorStyle == STYLE_BLOCK ? -1 : 2)));
indicatorWidth = ta.getDimension(R.styleable.CommonTabLayout_tl_indicator_width, dp2px(indicatorStyle == STYLE_TRIANGLE ? 10 : -1));
Expand Down Expand Up @@ -201,8 +202,8 @@ public void setTabData(ArrayList<CustomTabEntity> tabEntitys) {
}

/** 关联数据支持同时切换fragments */
public void setTabData(ArrayList<CustomTabEntity> tabEntitys, FragmentManager fm, int containerViewId, ArrayList<Fragment> fragments) {
fragmentChangeManager = new FragmentChangeManager(fm, containerViewId, fragments);
public void setTabData(ArrayList<CustomTabEntity> tabEntitys, FragmentActivity fa, int containerViewId, ArrayList<Fragment> fragments) {
fragmentChangeManager = new FragmentChangeManager(fa.getSupportFragmentManager(), containerViewId, fragments);
setTabData(tabEntitys);
}

Expand Down Expand Up @@ -390,7 +391,7 @@ protected void onDraw(Canvas canvas) {
dividerPaint.setColor(dividerColor);
for (int i = 0; i < tabCount - 1; i++) {
View tab = tabsContainer.getChildAt(i);
canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
canvas.drawLine(paddingLeft + tab.getRight(), dividerPadding, paddingLeft + tab.getRight(), height - dividerPadding, dividerPaint);
}
}

Expand Down Expand Up @@ -524,13 +525,8 @@ public void setIndicatorCornerRadius(float indicatorCornerRadius) {
invalidate();
}

public void setUnderlineColor(int underlineColor) {
this.underlineColor = underlineColor;
invalidate();
}

public void setUnderlineHeight(float underlineHeight) {
this.underlineHeight = dp2px(underlineHeight);
public void setIndicatorGravity(int indicatorGravity) {
this.indicatorGravity = indicatorGravity;
invalidate();
}

Expand All @@ -555,6 +551,21 @@ public void setIndicatorBounceEnable(boolean indicatorBounceEnable) {
this.indicatorBounceEnable = indicatorBounceEnable;
}

public void setUnderlineColor(int underlineColor) {
this.underlineColor = underlineColor;
invalidate();
}

public void setUnderlineHeight(float underlineHeight) {
this.underlineHeight = dp2px(underlineHeight);
invalidate();
}

public void setUnderlineGravity(int underlineGravity) {
this.underlineGravity = underlineGravity;
invalidate();
}

public void setDividerColor(int dividerColor) {
this.dividerColor = dividerColor;
invalidate();
Expand Down
Loading

0 comments on commit 4cb128c

Please sign in to comment.