From 60add249282b85f5f9c59bae2280160141e9e4c1 Mon Sep 17 00:00:00 2001 From: hackware1993 Date: Tue, 22 Nov 2016 11:02:29 +0800 Subject: [PATCH] =?UTF-8?q?ClipPagerTitleView=E6=94=AF=E6=8C=81=E6=B5=8B?= =?UTF-8?q?=E9=87=8F=E5=86=85=E5=AE=B9=E5=8C=BA=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...vity_fragment_container_example_layout.xml | 5 --- .../titles/ClipPagerTitleView.java | 32 +++++++++++++++++-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/app/src/main/res/layout/activity_fragment_container_example_layout.xml b/app/src/main/res/layout/activity_fragment_container_example_layout.xml index 6cf6d4d6..5fdad93c 100644 --- a/app/src/main/res/layout/activity_fragment_container_example_layout.xml +++ b/app/src/main/res/layout/activity_fragment_container_example_layout.xml @@ -26,9 +26,4 @@ android:layout_height="0dp" android:layout_weight="1" /> - - diff --git a/magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/commonnavigator/titles/ClipPagerTitleView.java b/magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/commonnavigator/titles/ClipPagerTitleView.java index 83832dd1..01b71fdb 100644 --- a/magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/commonnavigator/titles/ClipPagerTitleView.java +++ b/magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/commonnavigator/titles/ClipPagerTitleView.java @@ -7,14 +7,14 @@ import android.view.View; import net.lucode.hackware.magicindicator.buildins.UIUtil; -import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IMeasurablePagerTitleView; /** * 类似今日头条切换效果的指示器标题 * 博客: http://hackware.lucode.net * Created by hackware on 2016/6/26. */ -public class ClipPagerTitleView extends View implements IPagerTitleView { +public class ClipPagerTitleView extends View implements IMeasurablePagerTitleView { private String mText; private int mTextColor; private int mClipColor; @@ -83,7 +83,7 @@ private int measureHeight(int heightMeasureSpec) { protected void onDraw(Canvas canvas) { int x = (getWidth() - mTextBounds.width()) / 2; Paint.FontMetrics fontMetrics = mPaint.getFontMetrics(); - int y = (int) (getHeight() / 2 - fontMetrics.bottom / 2 - fontMetrics.top / 2); + int y = (int) ((getHeight() - fontMetrics.bottom - fontMetrics.top) / 2); // 画底层 mPaint.setColor(mTextColor); @@ -162,4 +162,30 @@ public void setClipColor(int clipColor) { mClipColor = clipColor; invalidate(); } + + @Override + public int getContentLeft() { + int contentWidth = mTextBounds.width(); + return getLeft() + getWidth() / 2 - contentWidth / 2; + } + + @Override + public int getContentTop() { + Paint.FontMetrics metrics = mPaint.getFontMetrics(); + float contentHeight = metrics.bottom - metrics.top; + return (int) (getHeight() / 2 - contentHeight / 2); + } + + @Override + public int getContentRight() { + int contentWidth = mTextBounds.width(); + return getLeft() + getWidth() / 2 + contentWidth / 2; + } + + @Override + public int getContentBottom() { + Paint.FontMetrics metrics = mPaint.getFontMetrics(); + float contentHeight = metrics.bottom - metrics.top; + return (int) (getHeight() / 2 + contentHeight / 2); + } }