Search in sources :

Example 1 with AbViewPagerAdapter

use of com.ningcui.mylibrary.app.adapter.AbViewPagerAdapter in project JustAndroid by chinaltz.

the class AbPlayView method initView.

/**
	 * 初始化这个View.
	 * @param context the context
	 */
public void initView(Context context) {
    this.context = context;
    navLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    this.setOrientation(LinearLayout.VERTICAL);
    RelativeLayout mRelativeLayout = new RelativeLayout(context);
    mViewPager = new AbInnerViewPager(context);
    //手动创建的ViewPager,如果用fragment必须调用setId()方法设置一个id
    mViewPager.setId(R.id.view_pager);
    //导航的点
    mNavLayoutParent = new LinearLayout(context);
    mNavLayoutParent.setPadding(0, 5, 0, 5);
    navLinearLayout = new LinearLayout(context);
    navLinearLayout.setPadding(15, 1, 15, 1);
    navLinearLayout.setVisibility(View.INVISIBLE);
    mNavLayoutParent.addView(navLinearLayout, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    mRelativeLayout.addView(mViewPager, lp1);
    RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lp2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    mRelativeLayout.addView(mNavLayoutParent, lp2);
    addView(mRelativeLayout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    mViewList = new ArrayList<View>();
    mViewPagerAdapter = new AbViewPagerAdapter(context, mViewList);
    mViewPager.setAdapter(mViewPagerAdapter);
    mViewPager.setFadingEdgeLength(0);
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            makesurePosition();
            onPageSelectedCallBack(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            onPageScrolledCallBack(position);
        }
    });
}
Also used : RelativeLayout(android.widget.RelativeLayout) OnPageChangeListener(android.support.v4.view.ViewPager.OnPageChangeListener) ImageView(android.widget.ImageView) View(android.view.View) AbsListView(android.widget.AbsListView) ScrollView(android.widget.ScrollView) ListView(android.widget.ListView) LinearLayout(android.widget.LinearLayout) AbViewPagerAdapter(com.ningcui.mylibrary.app.adapter.AbViewPagerAdapter)

Aggregations

OnPageChangeListener (android.support.v4.view.ViewPager.OnPageChangeListener)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 RelativeLayout (android.widget.RelativeLayout)1 ScrollView (android.widget.ScrollView)1 AbViewPagerAdapter (com.ningcui.mylibrary.app.adapter.AbViewPagerAdapter)1