您好我已经创建了一个视图寻呼机但有没有人知道如何在页面视图中显示代表分页的圈子我觉得它已经指出了一个指标,但我不完全确定?
到目前为止,包含我的查看分页器的代码
public class LevelSelect extends Activity {
private ViewPager awesomePager;
private static int NUM_AWESOME_VIEWS = 10;
private Context cxt;
private AwesomePagerAdapter awesomeAdapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_levelselect);
cxt = this;
awesomeAdapter = new AwesomePagerAdapter();
awesomePager = (ViewPager) findViewById(R.id.viewpager);
awesomePager.setAdapter(awesomeAdapter);
}
private class AwesomePagerAdapter extends PagerAdapter{
@Override
public int getCount() {
return NUM_AWESOME_VIEWS;
}
@Override
public Object instantiateItem(View collection, int position) {
LayoutInflater mLayoutInflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View LeagueButtonView = mLayoutInflater.inflate(R.layout.ls_button, null);
Button LeagueButton = (Button) LeagueButtonView.findViewById(R.id.league);
LeagueButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.ls_level_eng1_locked));
((ViewPager) collection).addView(LeagueButtonView,0);
return LeagueButtonView;
}
@Override
public void destroyItem(View collection, int position, Object view) {
((ViewPager) collection).removeView((View) view);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==((View)object);
}
@Override
public void finishUpdate(View arg0) {}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View arg0) {}
}
答案 0 :(得分:15)
您可以使用Jake Wharton的ViewPagerIndicator为ViewPager中的每个标签添加标题或简单的圆圈。
Jake Wharton在GitHub上提供了大量示例代码,您也可以参考Jake Wharton网站上的usage section。
您还可以使用Greendroid library
的ViewPager和PageIndicator
答案 1 :(得分:0)
拍摄两张图像(圆圈或任何其他形状图像,一张为另一张图像)。采用一个框架布局,在框架上显示图像(指示器)。当用户更改图像时,显示正确的指示器。
我已经实现了这个并且工作正常。您可以download代码并相应地进行更改。