17

嗨,我创建了一个视图寻呼机,但有谁知道我如何在页面视图上显示代表分页的圆圈,我认为它暗示了一个指标,但我不完全确定?

继承人到目前为止包含我的视图寻呼机的代码

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) {}

    }
4

2 回答 2

14

You can use Jake Wharton's ViewPagerIndicator to add the titles or simple circles for each tab in your ViewPager.

Jake Wharton has supplied a bunch of sample code on GitHub, you can also refer to the usage section on the Jake Wharton's site.

enter image description here

You can also use the ViewPager and PageIndicator of Greendroid library

enter image description here

于 2012-07-14T18:47:53.520 回答
1

拍摄两个图像(圆形或任何其他形状的图像,一个用于关闭另一个用于打开)。采用一帧布局,在帧上显示图像(指示器)。当用户更改图像时,显示正确的指示器。

我已经实现了这一点并且工作正常。您可以下载代码并进行相应更改。 在此处输入图像描述

于 2016-01-13T16:15:22.480 回答