use of android.support.v4.view.ViewPager in project realm-java by realm.
the class ThreadExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set up the action bar.
final android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(android.support.v7.app.ActionBar.NAVIGATION_MODE_TABS);
SectionsPagerAdapter pageAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(pageAdapter);
viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < pageAdapter.getCount(); i++) {
getSupportActionBar().addTab(getSupportActionBar().newTab().setText(pageAdapter.getPageTitle(i)).setTabListener(this));
}
}
use of android.support.v4.view.ViewPager in project hellocharts-android by lecho.
the class ViewPagerChartsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_pager_charts);
// Set up the action bar.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
// For each of the sections in the app, add a tab to the action bar.
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
// Create a tab with text corresponding to the page title defined by
// the adapter. Also specify this Activity object, which implements
// the TabListener interface, as the callback (listener) for when
// this tab is selected.
actionBar.addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
}
}
use of android.support.v4.view.ViewPager in project ParallaxSplash by leerduo.
the class ParallaxContainer method setUp.
/**
* 指定引导页的所有页面布局文件
*
* @param childIds
*/
public void setUp(int... childIds) {
//根据布局文件数组,初始化所有的Fragment
fragments = new ArrayList<>();
for (int i = 0; i < childIds.length; i++) {
ParallaxFragment f = new ParallaxFragment();
Bundle args = new Bundle();
//页面索引
args.putInt("index", i);
//Fragment中需要加载的布局文件id
args.putInt("layoutId", childIds[i]);
f.setArguments(args);
fragments.add(f);
}
//实例化适配器
MainActivity activity = (MainActivity) getContext();
adapter = new ParallaxPagerAdapter(activity.getSupportFragmentManager(), fragments);
//实例化ViewPager
ViewPager vp = new ViewPager(getContext());
vp.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
vp.setId(R.id.parallax_pager);
//绑定
vp.setAdapter(adapter);
addView(vp, 0);
//在翻页的过程中,不断根据视图的标签中对应的动画参数,改变视图的位置或者透明度
vp.setOnPageChangeListener(this);
}
use of android.support.v4.view.ViewPager in project android-Ultra-Pull-To-Refresh by liaohuqiu.
the class ViewPagerActivity method initCateViews.
private void initCateViews() {
int startIndex = 0;
mCatTabPageIndicator = (TabPageIndicator) findViewById(R.id.view_pager_tab_indicator);
mFragmentViewPager = (ViewPager) this.findViewById(R.id.view_pager_view_pager);
ArrayList<ViewPagerFragment> list = new ArrayList<ViewPagerFragment>();
for (int i = 1; i <= 8; i++) {
list.add(ViewPagerFragment.create(i));
}
mPagerAdapter = new FragmentViewPagerAdapter(getSupportFragmentManager(), list);
mFragmentViewPager.setAdapter(mPagerAdapter);
mCatTabPageIndicator.setViewHolderCreator(new TabPageIndicator.ViewHolderCreator() {
@Override
public TabPageIndicator.ViewHolderBase createViewHolder() {
return new HomeCatItemViewHolder();
}
});
mCatTabPageIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int i) {
switchTo(i);
}
});
mCatTabPageIndicator.setViewPager(mFragmentViewPager);
mPtrFrame = (PtrClassicFrameLayout) findViewById(R.id.view_pager_ptr_frame);
mPtrFrame.disableWhenHorizontalMove(true);
mPtrFrame.setPtrHandler(new PtrHandler() {
@Override
public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
return mPagerAdapter.checkCanDoRefresh();
}
@Override
public void onRefreshBegin(PtrFrameLayout frame) {
mPagerAdapter.updateData();
}
});
mFragmentViewPager.setCurrentItem(startIndex);
}
use of android.support.v4.view.ViewPager in project TransitionPlayer by linfaxin.
the class XiaoMaIntroDemo method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo_xiaoma_intro);
extraPager = (ViewPager) findViewById(R.id.extra_pager);
initSmoothScrollToViewPager(extraPager);
mStartBtn = findViewById(R.id.start);
View.OnClickListener finishClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
};
mStartBtn.setOnClickListener(finishClick);
mStartBtn.setVisibility(View.INVISIBLE);
mPathBtn = findViewById(R.id.through);
mPathBtn.setOnClickListener(finishClick);
mShowAnimation = new AlphaAnimation(0.0f, 1.0f);
mHideAnimation = new AlphaAnimation(1.0f, 0.0f);
mTextHideAnimation = new AlphaAnimation(1.0f, 0.0f);
mShowAnimation.setDuration(400);
mHideAnimation.setDuration(400);
mTextHideAnimation.setDuration(400);
mShowAnimation.setFillAfter(true);
mHideAnimation.setFillAfter(true);
mTextHideAnimation.setFillAfter(true);
final List<View> viewArray = new ArrayList<View>();
View view1 = View.inflate(this, R.layout.xiaoma_intro_page_base, null);
((ImageView) view1.findViewById(R.id.title)).setImageResource(R.drawable.xiaoma_intro_top_text1);
view1.findViewById(R.id.description).setVisibility(View.VISIBLE);
viewArray.add(view1);
View view2 = View.inflate(this, R.layout.xiaoma_intro_page_base, null);
((ImageView) view2.findViewById(R.id.title)).setImageResource(R.drawable.xiaoma_intro_top_text2);
view2.findViewById(R.id.description).setVisibility(View.GONE);
viewArray.add(view2);
View view3 = View.inflate(this, R.layout.xiaoma_intro_page_base, null);
((ImageView) view3.findViewById(R.id.title)).setImageResource(R.drawable.xiaoma_intro_top_text3);
view3.findViewById(R.id.description).setVisibility(View.GONE);
viewArray.add(view3);
View view4 = View.inflate(this, R.layout.xiaoma_intro_page_base, null);
((ImageView) view4.findViewById(R.id.title)).setImageResource(R.drawable.xiaoma_intro_top_text4);
view4.findViewById(R.id.description).setVisibility(View.GONE);
viewArray.add(view4);
pageScene1_2 = Scene.getSceneForLayout((ViewGroup) findViewById(R.id.root_view_1_to_2), R.layout.xiaoma_intro_scene2, this);
pageScene2_3 = Scene.getSceneForLayout((ViewGroup) findViewById(R.id.root_view_2_to_3), R.layout.xiaoma_intro_scene3, this);
pageScene3_4 = Scene.getSceneForLayout((ViewGroup) findViewById(R.id.root_view_3_to_4), R.layout.xiaoma_intro_scene4, this);
extraPager.postDelayed(new Runnable() {
@Override
public void run() {
TransitionManager.go(pageScene1_2, customTransition1_2);
TransitionManager.go(pageScene2_3, customTransition2_3);
TransitionManager.go(pageScene3_4, customTransition3_4);
}
}, 50);
mTextSceneRoot = (ViewGroup) findViewById(R.id.text_root_view);
textScene1 = Scene.getSceneForLayout(mTextSceneRoot, R.layout.xiaoma_intro_scene1_text, this);
textScene2 = Scene.getSceneForLayout(mTextSceneRoot, R.layout.xiaoma_intro_scene2_text, this);
textScene3 = Scene.getSceneForLayout(mTextSceneRoot, R.layout.xiaoma_intro_scene3_text, this);
textScene4 = Scene.getSceneForLayout(mTextSceneRoot, R.layout.xiaoma_intro_scene4_text, this);
extraPager.setAdapter(new PagerAdapter() {
@Override
public int getCount() {
return 4;
}
@Override
public boolean isViewFromObject(View view, Object o) {
return view == o;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
container.addView(viewArray.get(position));
return viewArray.get(position);
}
});
extraPager.addOnPageChangeListener(this);
}
Aggregations