|
7 | 7 | import android.view.View; |
8 | 8 |
|
9 | 9 | import net.lucode.hackware.magicindicator.buildins.UIUtil; |
10 | | -import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView; |
| 10 | +import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IMeasurablePagerTitleView; |
11 | 11 |
|
12 | 12 | /** |
13 | 13 | * 类似今日头条切换效果的指示器标题 |
14 | 14 | * 博客: http://hackware.lucode.net |
15 | 15 | * Created by hackware on 2016/6/26. |
16 | 16 | */ |
17 | | -public class ClipPagerTitleView extends View implements IPagerTitleView { |
| 17 | +public class ClipPagerTitleView extends View implements IMeasurablePagerTitleView { |
18 | 18 | private String mText; |
19 | 19 | private int mTextColor; |
20 | 20 | private int mClipColor; |
@@ -83,7 +83,7 @@ private int measureHeight(int heightMeasureSpec) { |
83 | 83 | protected void onDraw(Canvas canvas) { |
84 | 84 | int x = (getWidth() - mTextBounds.width()) / 2; |
85 | 85 | Paint.FontMetrics fontMetrics = mPaint.getFontMetrics(); |
86 | | - int y = (int) (getHeight() / 2 - fontMetrics.bottom / 2 - fontMetrics.top / 2); |
| 86 | + int y = (int) ((getHeight() - fontMetrics.bottom - fontMetrics.top) / 2); |
87 | 87 |
|
88 | 88 | // 画底层 |
89 | 89 | mPaint.setColor(mTextColor); |
@@ -162,4 +162,30 @@ public void setClipColor(int clipColor) { |
162 | 162 | mClipColor = clipColor; |
163 | 163 | invalidate(); |
164 | 164 | } |
| 165 | + |
| 166 | + @Override |
| 167 | + public int getContentLeft() { |
| 168 | + int contentWidth = mTextBounds.width(); |
| 169 | + return getLeft() + getWidth() / 2 - contentWidth / 2; |
| 170 | + } |
| 171 | + |
| 172 | + @Override |
| 173 | + public int getContentTop() { |
| 174 | + Paint.FontMetrics metrics = mPaint.getFontMetrics(); |
| 175 | + float contentHeight = metrics.bottom - metrics.top; |
| 176 | + return (int) (getHeight() / 2 - contentHeight / 2); |
| 177 | + } |
| 178 | + |
| 179 | + @Override |
| 180 | + public int getContentRight() { |
| 181 | + int contentWidth = mTextBounds.width(); |
| 182 | + return getLeft() + getWidth() / 2 + contentWidth / 2; |
| 183 | + } |
| 184 | + |
| 185 | + @Override |
| 186 | + public int getContentBottom() { |
| 187 | + Paint.FontMetrics metrics = mPaint.getFontMetrics(); |
| 188 | + float contentHeight = metrics.bottom - metrics.top; |
| 189 | + return (int) (getHeight() / 2 + contentHeight / 2); |
| 190 | + } |
165 | 191 | } |
0 commit comments