相反,我建议你在相同的布局使用简单的水平的LinearLayout与ViewPager,在它下面。并使用ViewPager中的页面填充此LinearLayout的尽可能多的TextView。将每个TextView的圆圈html代码作为文本。只需简单地使用textView.setText(Html.fromHtml("○"));
然后动态更改页面更改时所选圆圈的颜色,并在每个TextView上添加onClickListener以更改ViewPager上的页面。使用相同的想法here。注意方法addBottomDots:
private void addBottomDots(int currentPage) {
dots = new TextView[layouts.length];
int[] colorsActive = getResources().getIntArray(R.array.array_for_active_dot);
int[] colorsInactive = getResources().getIntArray(R.array.array_for_inactive_dot);
dotsLayout.removeAllViews();
for (int i = 0; i < dots.length; i++) {
dots[i] = new TextView(this);
dots[i].setText(Html.fromHtml("•"));
dots[i].setTextSize(35);
dots[i].setTextColor(colorsInactive[currentPage]);
dotsLayout.addView(dots[i]);
}
if (dots.length > 0)
dots[currentPage].setTextColor(colorsActive[currentPage]);
}
,并调用它每次页面变化:
public void onPageSelected(int position) {
addBottomDots(position);
//... and so on, your code goes here
}
希望它能帮助。