0

我正在使用 JakeWharton TitlePageIndicator。在我将标题设置为有点长的字符串(20 个字符)之前,该指标一直很有效,中心标题显示得很好,但左右标题离中心标题太近了。有没有办法让它就像在谷歌播放中一样,左右标题只显示一半(或固定长度)?

谢谢,

4

2 回答 2

2

您不需要像那样修改库。只需为 TitlePageIndicator 指定一个 clipPadding。

像那样 :

mIndicator.setClipPadding(-60);
于 2013-02-21T13:21:55.577 回答
2

对于任何可能有同样问题的人。在 JakeWharton TitlePageIndicator 中,有两种方法可以控制左右标题的显示:

/**
 * Set bounds for the right textView including clip padding.
 *
 * @param curViewBound
 *            current bounds.
 * @param curViewWidth
 *            width of the view.
 */
private void clipViewOnTheRight(Rect curViewBound, float curViewWidth, int right) {
    // isShowPartOfInactiveTitles is my variable which is set default to TRUE
    if(isShowPartOfInactiveTitles){
        curViewBound.right = (int)(right + curViewWidth - 60);
        curViewBound.left = (int)(right - 60);
    }else{
        curViewBound.right = (int) (right - mClipPadding);
        curViewBound.left = (int) (curViewBound.right - curViewWidth);
    }
}

/**
 * Set bounds for the left textView including clip padding.
 *
 * @param curViewBound
 *            current bounds.
 * @param curViewWidth
 *            width of the view.
 */
private void clipViewOnTheLeft(Rect curViewBound, float curViewWidth, int left) {
    // isShowPartOfInactiveTitles is my variable which is set default to TRUE
    if(isShowPartOfInactiveTitles){
        curViewBound.left = (int)(left - curViewWidth + 60);
        curViewBound.right = (int)(left + 60);
    }else{
        curViewBound.left = (int) (left + mClipPadding);
        curViewBound.right = (int) (mClipPadding + curViewWidth);   
    }
}

上面的代码片段将只显示 60dp 的左右标题。您可以将此数字作为属性并通过 xml 传递。为了便于理解,我在这里对其进行了硬编码。

于 2013-01-09T07:08:34.067 回答