HorizontalScrollView里的标签改变颜色(今日头条里的功能仿照)

private void selectTab(int position) {
// TODO Auto-generated method stub

for (int i = 0; i < hori_lin.getChildCount(); i++) {
TextView childAt = (TextView) hori_lin.getChildAt(position);
// 字体的长度;
int k = childAt.getMeasuredWidth();
// 从字体到屏幕左边的距离;
int l = childAt.getLeft();

int s = l + k / 2 - mscreenwidth / 2;
horizontalScrollView.smoothScrollTo(s, 0);

TextView child = (TextView) hori_lin.getChildAt(i);
if (position == i) {

child.setTextColor(Color.RED);

} else {
child.setTextColor(Color.BLACK);
}

}

}

原文地址:https://www.cnblogs.com/zhengyanyan/p/5300516.html