我是 android 新手,在我的应用程序中我正在使用圆形指示器。但我不知道如何添加它.. 谁能告诉我如何在我的代码中添加圆形指示器。这是我的代码
public class WalkthroughActivity extends Activity {
private static final int MAX_VIEWS = 5;
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(new WalkthroughPagerAdapter());
mViewPager.setOnPageChangeListener(new WalkthroughPageChangeListener());
}
class WalkthroughPagerAdapter extends PagerAdapter {
@Override
public int getCount() {
return MAX_VIEWS;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == (View) object;
}
@Override
public Object instantiateItem(View container, int position) {
Log.e("walkthrough", "instantiateItem(" + position + ");");
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View imageViewContainer = inflater.inflate(R.layout.activity_view_pager, null);
ImageView imageView = (ImageView) imageViewContainer.findViewById(R.id.imageView1);
switch(position) {
case 0:
imageView.setImageResource(R.drawable.kierkegaarddrop);
break;
case 1:
imageView.setImageResource(R.drawable.nature);
break;
case 2:
imageView.setImageResource(R.drawable.path);
break;
case 3:
imageView.setImageResource(R.drawable.supportlife);
break;
case 4:
imageView.setImageResource(R.drawable.willow);
break;
}
((ViewPager) container).addView(imageViewContainer, 0);
return imageViewContainer;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager)container).removeView((View)object);
}
}
class WalkthroughPageChangeListener implements ViewPager.OnPageChangeListener {
@Override
public void onPageScrollStateChanged(int arg0) {
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageSelected(int position) {
// Here is where you should show change the view of page indicator
switch(position) {
case MAX_VIEWS - 1:
break;
default:
}
}
}