Android 杰克·沃顿标题页指示器:如何只显示左右标题的一半
我用的是杰克·沃顿的标题页指示器。指示器工作得非常好,直到我将标题设置为一个稍长的字符串(20个字符),中心标题显示得非常好,但左侧和右侧标题与中心标题太接近。有没有办法让它像Google play一样,左右标题只显示一半(或固定长度)Android 杰克·沃顿标题页指示器:如何只显示左右标题的一半,android,viewpagerindicator,Android,Viewpagerindicator,我用的是杰克·沃顿的标题页指示器。指示器工作得非常好,直到我将标题设置为一个稍长的字符串(20个字符),中心标题显示得非常好,但左侧和右侧标题与中心标题太接近。有没有办法让它像Google play一样,左右标题只显示一半(或固定长度) 谢谢您,对于可能有同样问题的任何人。在JakeWharton TitlePageIndicator中,有两种方法控制左右标题的显示: /** * Set bounds for the right textView including clip padding.
谢谢您,对于可能有同样问题的任何人。在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传递它。为了便于理解,我在这里对其进行了硬编码 适用于可能有同样问题的任何人。在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传递它。为了便于理解,我在这里对其进行了硬编码 您不需要这样修改库。 只需为TitlePageIndicator指定一个clipPadding 就像这样:
mIndicator.setClipPadding(-60);
您不需要像那样修改库。 只需为TitlePageIndicator指定一个clipPadding 就像这样:
mIndicator.setClipPadding(-60);
这个图书馆是开源的。也许你会深入研究代码,然后自己修改标题?@WarrenFaith:我试着深入研究代码。我看到有一个变量MCLIPPADING,但是这个变量控制左标题和左边缘(以及右标题和右边缘)之间的填充。我找不到控制左/右标题与中心标题之间距离的变量。你能给我一些线索吗?这个图书馆是开源的。也许你会深入研究代码,然后自己修改标题?@WarrenFaith:我试着深入研究代码。我看到有一个变量MCLIPPADING,但是这个变量控制左标题和左边缘(以及右标题和右边缘)之间的填充。我找不到控制左/右标题与中心标题之间距离的变量。你能给我一些线索吗?正如我在上面回复WarrenFaith的那样,mClipPadding控制着标题和边缘之间的距离。如果我将剪辑填充设置为-60,它将隐藏左标题和右标题60dip,但我需要的是仅显示左标题和右标题,例如60dip。这就是为什么我来修改库作为下面的答案。正如我在上面回答WarrenFaith,mClipPadding控制标题和边缘之间的距离。如果我将剪辑填充设置为-60,它将隐藏左标题和右标题60dip,但我需要的是仅显示左标题和右标题,例如60dip。这就是我来修改库的原因,答案如下。