Skip to content

Commit

Permalink
处理tab滚动之后,颜色和移动不对问题
Browse files Browse the repository at this point in the history
  • Loading branch information
LillteZheng committed Mar 8, 2019
1 parent b7831c9 commit cb5a795
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
testCompile 'junit:junit:4.12'
//调试的时候,可以使用这种加载 module的方式
compile project(':viewpagerlib')
//implementation 'com.github.LillteZheng:ViewPagerHelper:v1.1'
//implementation 'com.github.LillteZheng:ViewPagerHelper:v1.2'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'

Expand Down
1 change: 0 additions & 1 deletion viewpagerlib/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/build
.idea/
gradle/
.gradle/
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class TabIndicator extends LinearLayout implements ViewPager.OnPageChange
private float mSnap;
private float mDownX,mMoveX;
private float mLastMoveX;
private boolean isColorMove;

public TabIndicator(Context context) {
this(context,null);
Expand Down Expand Up @@ -174,7 +175,7 @@ public boolean onTouchEvent(MotionEvent event) {
return true;
}
scrollBy(scrolledX, 0);

isColorMove = true;
mLastMoveX = mMoveX;
break;
case MotionEvent.ACTION_UP :
Expand All @@ -201,10 +202,7 @@ public void computeScroll() {
protected void onFinishInflate() {
super.onFinishInflate();
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);

mWidth = wm.getDefaultDisplay().getWidth();


}

/**
Expand Down Expand Up @@ -281,6 +279,13 @@ public void setTabData(final ViewPager viewPager, final List<String> titles,
@Override
public void onClick(View view) {
listener.onClick(finalI);
//在点击的时候,我们需要做一些处理
int moveX = getScrollX();
if (moveX < 1920) {
mScroller.startScroll(0, 0, 0, 0);
invalidate();
}

}
});
}
Expand All @@ -293,8 +298,6 @@ public void onClick(View view) {





@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
Expand Down Expand Up @@ -367,11 +370,22 @@ private void onScroll(int position, float offset) {
if (mTextType == COLOR_TEXT) {
if (offset >= 0) {
try {
//避免移动之后,颜色不对问题
if (isColorMove){
int count = getChildCount();
for (int i = 0; i < count; i++) {
ColorTextView textView = (ColorTextView) getChildAt(i);
textView.setTextColor(mDefaultColor);
}
ColorTextView textView = (ColorTextView) getChildAt(position);
textView.setTextColor(mChangeColor);
isColorMove = false;
}
ColorTextView leftView = (ColorTextView) getChildAt(position);
ColorTextView rightView = (ColorTextView) getChildAt(position + 1);

leftView.setprogress(1 - offset, ColorTextView.DEC_RIGHT);
rightView.setprogress(offset, ColorTextView.DEC_LEFT);

} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit cb5a795

Please sign in to comment.