这是您自己解决的超级简单的示例,这是一个示例。
在 ViewPager 下方添加一个 LinearLayout(@+id/indContainer) ,然后使用此代码设置点:
LinearLayout indContainer = (LinearLayout) findViewById(R.id.indicator_container);
for(int x=0;x<yourData.size();x++){
ImageView v = new ImageView(this);
int px = (int)(4 * (getResources().getDisplayMetrics().densityDpi / 160));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayoutCompat.LayoutParams.WRAP_CONTENT, LinearLayoutCompat.LayoutParams.WRAP_CONTENT);
params.setMargins(px,0,px,0);
v.setLayoutParams(params);
v.setImageResource(R.drawable.indicator_inactive);
indContainer.addView(v);
}
然后在您的 pageChangeListener 中:
LinearLayout indContainer = (LinearLayout) findViewById(R.id.indicator_container);
((ImageView) indContainer.getChildAt(position)).setImageResource(R.drawable.indicator_active);
((ImageView) indContainer.getChildAt(lastPage)).setImageResource(R.drawable.indicator_inactive);
lastPage = position;
根据需要调整指示器图标和大小