在Android应用中向已查看的页面添加指示符图标

时间:2014-09-01 12:33:58

标签: android eclipse

我正在尝试向我的片段添加一个图标页面指示器并且我停止工作错误?有人可以帮助我如何在我的指示器中放置图标吗?我可以添加圆形页面指示器但图标页面指示器给我“已停止工作“错误。 这是我的.java代码

public class Levels extends FragmentActivity {
    IconPageIndicator mIndicator;
    Button startgamebtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.levels);

        float pixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                500, getResources().getDisplayMetrics());

        ViewPager viewpager = (ViewPager) findViewById(R.id.pager);
        DisplayMetrics displaymetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        int width = displaymetrics.widthPixels;
        int height = displaymetrics.heightPixels;
        viewpager.getLayoutParams().height = (int) (height*3)/4;
        viewpager.setAdapter(new myAdapter(getSupportFragmentManager()));

        mIndicator = (IconPageIndicator)findViewById(R.id.Title);
        mIndicator.setViewPager(viewpager);

        final float density = getResources().getDisplayMetrics().density;


    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();

    }
}

class myAdapter extends FragmentPagerAdapter {

    public myAdapter(FragmentManager fm) {
        super(fm);
        // TODO Auto-generated constructor stub
    }

    @Override
    public Fragment getItem(int id) {
        Fragment fr = null;

        if (id == 0)
            fr = new LevelA();

        if (id == 1)
            fr = new LevelB();

        if (id == 2)
            fr = new LevelC();

        if (id == 3)
            fr = new LevelD();

        return fr;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return 4;
    }

}

这是我的.xml代码

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignParentBottom="true"
        >

        <android.support.v4.view.ViewPager
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/pager"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </android.support.v4.view.ViewPager>

        <com.viewpagerindicator.IconPageIndicator
            android:id="@+id/Title"
            android:layout_marginTop="25dp"
            android:padding="2dp"
           android:layout_marginBottom="20sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

</RelativeLayout>

0 个答案:

没有答案