private void setCircleTab() {
/**
* 初始化小圆点
*/
LinearLayout.LayoutParams margin = new LinearLayout.LayoutParams(28, 28);
margin.setMargins(4, 0, 0, 0);
layout_group.removeAllViews();
imageViews = new ImageView[locations.length];
for (int i = 0; i < locations.length; i++) {
ImageView imageView = new ImageView(MainActivity.this);
imageView.setLayoutParams(new LinearLayout.LayoutParams(16, 16));
imageViews[i] = imageView;
if (i == 0) {
imageViews[i].setImageResource(R.mipmap.circle_white_32);
} else {
imageViews[i].setImageResource(R.mipmap.circle_gray_32);
}
layout_group.addView(imageViews[i], margin);
}
}
下面的代码在Viewpager的OnPageChangeListener中的onPageSelecter方法中使用,实现白色小点跟随Viewpager滑动
/**
* 选项卡切换时,切换小圆点
*
* @param postion
*/
private void selectCircle(int postion) {
for (int i = 0; i < imageViews.length; i++) {
imageViews[postion].setImageResource(R.mipmap.circle_white_32);
if (postion != i) {
imageViews[i].setImageResource(R.mipmap.circle_gray_32);
}
}
}
LinearLayout的代码,居中显示效果较好
<LinearLayout
android:id="@+id/layout_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="2dp"
android:orientation="horizontal"></LinearLayout>