使用ViewPager指标与杰克沃顿图书馆的问题

时间:2015-07-21 01:56:56

标签: java android android-viewpager android-adapter viewpagerindicator

我已经下载了这个库并正确地包含在我的android studio项目中 使用库后,我无法看到Circle指示符: 这是我的代码:

主要文件:

 public class MyActivity extends FragmentActivity implements  OnPageChangeListener {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_my);
            List<Fragment> list = new ArrayList<Fragment>();
            list.add(new MyFragment());
            list.add(new MyFragment());
            list.add(new MyFragment());
            MyPagerAdapter a = new MyPagerAdapter(getSupportFragmentManager(), list);
           ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
            pager.setAdapter(a);
            CirclePageIndicator mIndicator = (CirclePageIndicator)findViewById(R.id.indicator);
            mIndicator.setViewPager(pager);


        }

MyPagerAdapter.java

public class MyPagerAdapter extends FragmentPagerAdapter {
    List<Fragment> fragments;
    public MyPagerAdapter(FragmentManager fm,List<Fragment> f) {
        super(fm);
        this.fragments = f;
    }

    @Override
    public Fragment getItem(int arg0) {

        return fragments.get(arg0);
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return fragments.size();
    }
}

MyFragment:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanse) {
        final View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        return rootView;
    }

activity_my.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
        <com.viewpagerindicator.CirclePageIndicator
            android:id="@+id/indicator"
            android:padding="10dip"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            />
</android.support.v4.view.ViewPager>

</RelativeLayout>

fragment_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/gallery"
        android:src="@drawable/pic1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

输出: Output

0 个答案:

没有答案