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);
}
});
}
Aggregations