当前位置: 首页>>代码示例>>Java>>正文


Java ViewPager.setOffscreenPageLimit方法代码示例

本文整理汇总了Java中android.support.v4.view.ViewPager.setOffscreenPageLimit方法的典型用法代码示例。如果您正苦于以下问题:Java ViewPager.setOffscreenPageLimit方法的具体用法?Java ViewPager.setOffscreenPageLimit怎么用?Java ViewPager.setOffscreenPageLimit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.view.ViewPager的用法示例。


在下文中一共展示了ViewPager.setOffscreenPageLimit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onViewCreated

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
    ViewPager viewPager = view.findViewById(R.id.viewpager);
    viewPager.setOffscreenPageLimit(1);
    setupViewPager(viewPager);

    TabLayout tabLayout = view.findViewById(R.id.tablayout);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);

    int tabColorPrimary = CurrentTheme.getPrimaryTextColorOnColoredBackgroundCode(getActivity());
    int tabColorSecondary = CurrentTheme.getSecondaryTextColorOnColoredBackgroundCode(getActivity());
    tabLayout.setTabTextColors(tabColorSecondary, tabColorPrimary);
    tabLayout.setupWithViewPager(viewPager);

    if(getArguments().containsKey(Extra.TAB)){
        int tab = getArguments().getInt(Extra.TAB);
        getArguments().remove(Extra.TAB);
        viewPager.setCurrentItem(tab);
    }
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:22,代码来源:FaveTabsFragment.java

示例2: onCreate

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mViewPager = (ViewPager) findViewById(R.id.viewPager);
    mButton = (Button) findViewById(R.id.cardTypeBtn);
    ((CheckBox) findViewById(R.id.checkBox)).setOnCheckedChangeListener(this);
    mButton.setOnClickListener(this);

    mCardAdapter = new CardPagerAdapter();
    mCardAdapter.addCardItem(new CardItem(R.string.title_1, R.string.text_1));
    mCardAdapter.addCardItem(new CardItem(R.string.title_2, R.string.text_1));
    mCardAdapter.addCardItem(new CardItem(R.string.title_3, R.string.text_1));
    mCardAdapter.addCardItem(new CardItem(R.string.title_4, R.string.text_1));
    mFragmentCardAdapter = new CardFragmentPagerAdapter(getSupportFragmentManager(),
            dpToPixels(2, this));

    mCardShadowTransformer = new ShadowTransformer(mViewPager, mCardAdapter);
    mFragmentCardShadowTransformer = new ShadowTransformer(mViewPager, mFragmentCardAdapter);

    mViewPager.setAdapter(mCardAdapter);
    mViewPager.setPageTransformer(false, mCardShadowTransformer);
    mViewPager.setOffscreenPageLimit(3);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:MainActivity.java

示例3: onCreate

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    tabLayout = (MainTabLayout) findViewById(R.id.main_activity_tab_layout);
    viewPager = (ViewPager) findViewById(R.id.main_activity_view_pager);

    pagerAdapter = createAdapter();
    viewPager.setOffscreenPageLimit(5);
    viewPager.setAdapter(pagerAdapter);
    tabLayout.setupWithViewPager(viewPager);

    viewPager.setCurrentItem(2);

    Intent intent = new Intent(this, LocationService.class);
    startService(intent);
}
 
开发者ID:KwalaGroup,项目名称:Android-Client,代码行数:19,代码来源:MainActivity.java

示例4: onCreate

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mIssueAdapter = AdapterFactory.getInstance().getIssueAdapter(this);
    setContentView(R.layout.create_issue_layout);

    mViewPager = (ViewPager) findViewById(R.id.viewpager);

    // Set an Adapter on the ViewPager
    mViewPager.setAdapter(new CreateIssuePagerAdapter(getSupportFragmentManager()));
    mViewPager.setCurrentItem(0);
    mViewPager.setOffscreenPageLimit(mViewPager.getAdapter().getCount() - 1);

    Toolbar toolbar = (Toolbar) findViewById(R.id.create_issue_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(getString(R.string.create_new_issue));

    setupCloseKeyboard(findViewById(android.R.id.content));
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:22,代码来源:CreateIssueActivity.java

示例5: onCreate

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.fragment_activity_layout);

    mViewPager = (ViewPager)findViewById(R.id.fragment_pager);

    imageFragment = Fragment.instantiate(this, ImageFragment.class.getName());
    textFragment = Fragment.instantiate(this, TextFragment.class.getName());
    image2Fragment = Fragment.instantiate(this, ImageFragment.class.getName());
    text2Fragment = Fragment.instantiate(this, TextFragment.class.getName());

    mViewPager.setOffscreenPageLimit(4);
    mViewPager.setCurrentItem(0);
    mViewPager.setAdapter(new FPagerAdapter(getSupportFragmentManager()));
}
 
开发者ID:zaneCC,项目名称:android_permission,代码行数:18,代码来源:FragmentActivity.java

示例6: setViewPager

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
private void setViewPager(ViewPager viewPager) {
    final FragmentTabAdapter tabAdapter = new FragmentTabAdapter(getSupportFragmentManager());
    tabAdapter.addFragment(new ScanFragment());
    viewPager.setAdapter(tabAdapter);

    // Avoid re-creating the camera fragment every time, it's too expensive and it's best to keep it alive when swiping
    viewPager.setOffscreenPageLimit(2); // Update this if needed

    viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            Log.d(TAG, "onPageSelected: " + position);

            mOldPage = mCurrentPage;
            mCurrentPage = position;

            PageChangedEvent event = new PageChangedEvent(mOldPage, mCurrentPage);
            event.setCurrentShownFragment(tabAdapter.getItem(position).getClass());
            RxBus.getInstance().postToEventBus(event);
        }
    });
}
 
开发者ID:dvdciri,项目名称:DeepImagePreview-Project,代码行数:24,代码来源:TabActivity.java

示例7: initview

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
private void initview() {
    FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
            getActivity().getSupportFragmentManager(), FragmentPagerItems.with(getActivity())
            .add(R.string.a, MainFragment.class)
            .add(R.string.b, SpecialFragment.class)
            .add(R.string.c, FriendsFragment.class)

            .create());

    ViewPager viewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
    viewPager.setOffscreenPageLimit(2);
    viewPager.setAdapter(adapter);

    SmartTabLayout viewPagerTab = (SmartTabLayout) rootView.findViewById(R.id.viewpagertab);
    viewPagerTab.setViewPager(viewPager);

}
 
开发者ID:Shmilyz,项目名称:Swap,代码行数:18,代码来源:ViewPagerFragmwnt.java

示例8: onCreate

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mUserAdapter = AdapterFactory.getInstance().getUserAdapter(getApplicationContext());
    mLoginAdapter = AdapterFactory.getInstance().getLoginAdapter(this);
    setContentView(R.layout.registration_layout);

    mViewPager = (ViewPager) findViewById(R.id.viewpager);

    // Set an Adapter on the ViewPager
    mViewPager.setAdapter(new RegistrationPagerAdapter(getSupportFragmentManager()));
    mViewPager.setCurrentItem(0);
    mViewPager.setOffscreenPageLimit(mViewPager.getAdapter().getCount() - 1);

    //noinspection ConstantConditions
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle("");
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:20,代码来源:RegistrationActivity.java

示例9: initViewPager

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
private void initViewPager() {
    Log.i(TAG, "initViewPager: -------------------------"+ indexString);
    mViewPager = (ViewPager) findViewById(R.id.vp_main);
    gankFragmentAdapter = new MainFragmentAdapter(getSupportFragmentManager(), mGankFragment, gankTitle);
    soFragmentAdapter = new MainFragmentAdapter(getSupportFragmentManager(), mSoFragment, soTitle);
    newsFragmentAdapter = new MainFragmentAdapter(getSupportFragmentManager(), mNewsFragment, newsTitle);
    switch (indexString) {
        case "Gank":
            navigationView.getMenu().getItem(0).setChecked(true);
            mViewPager.setOffscreenPageLimit(mGankFragment.size());
            mViewPager.setAdapter(gankFragmentAdapter);
            break;
        case "妹纸":
            navigationView.getMenu().getItem(1).setChecked(true);
            mViewPager.setOffscreenPageLimit(mNewsFragment.size());
            mViewPager.setAdapter(soFragmentAdapter);
            break;
        case "休闲":
            navigationView.getMenu().getItem(2).setChecked(true);
            mViewPager.setOffscreenPageLimit(mNewsFragment.size());
            mViewPager.setAdapter(newsFragmentAdapter);
            break;
    }
}
 
开发者ID:lueans,项目名称:LueansRead,代码行数:25,代码来源:MainActivity.java

示例10: onViewCreated

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ViewPager mViewPager = (ViewPager) view.findViewById(R.id.vp);
    FragmentPagerItems pages = new FragmentPagerItems(getActivity());
    final int page = FragmentPagerItem.getPosition(getArguments());

    for (int i = 0; i < 5; i++) {
        Bundle bundle = new Bundle();
        bundle.putInt("page", page);
        bundle.putInt("position", i);
        pages.add(FragmentPagerItem.of(String.valueOf(i), DemoFragment.class, bundle));
    }
    FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(getChildFragmentManager(), pages); //Fragment嵌套Fragment时,要用getChildFragmentManager
    mViewPager.setAdapter(adapter);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.setPageMargin(30);
    final MainActivity mainActivity = (MainActivity) getActivity();
    mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            mainActivity.pageScrolled(page, position, positionOffset);
        }
    });
}
 
开发者ID:simplezhli,项目名称:ChangeTabLayout,代码行数:26,代码来源:PageFragment.java

示例11: onCreate

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_movies);

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPager.setOffscreenPageLimit(4);
    setupViewPager(viewPager);

    TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
    tabs.setupWithViewPager(viewPager);
}
 
开发者ID:ansarisufiyan777,项目名称:Show_Chat,代码行数:13,代码来源:MoviesActivity.java

示例12: initMainViewPager

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
private void initMainViewPager() {
    Fragment conversationList = initConversationList();  //返回 Fragment
    mViewPager = (ViewPager) findViewById(R.id.main_viewpager);

    mUnreadNumView = (DragPointView) findViewById(R.id.seal_num);
    mUnreadNumView.setOnClickListener(this);
    mUnreadNumView.setDragListencer(this);

    mFragment.add(new ContactsFragment()); //蓝皮书

    mFragment.add(conversationList);  //正在聊天列表

    mFragment.add(new DiscoverFragment()); //消息
    mFragment.add(new MineFragment());  //个人

    FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            return mFragment.get(position);
        }

        @Override
        public int getCount() {
            return mFragment.size();
        }
    };
    mViewPager.setAdapter(fragmentPagerAdapter);
    mViewPager.setOffscreenPageLimit(4);
    mViewPager.setOnPageChangeListener(this);
    initData();
}
 
开发者ID:zqHero,项目名称:rongyunDemo,代码行数:32,代码来源:MainActivity.java

示例13: initPager

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
/**
 * 初始化 pager 绑定适配器
 */
private void initPager() {
    pager = (ViewPager) findViewById(R.id.main_viewpager);
    pager.setOffscreenPageLimit(1);
    List<Fragment> fragments = new ArrayList<>();
    fragments.add(new MainFragment());
    fragments.add(new NoteChatFragment());
    fragments.add(new UserInfoFragment());
    fragments.add(new ShoppingFragment());
    FragmentAdapter adapter = new FragmentAdapter(getSupportFragmentManager(), fragments);
    pager.setAdapter(adapter);
}
 
开发者ID:weimin96,项目名称:shareNote,代码行数:15,代码来源:MainActivity.java

示例14: onCreate

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_main);
    viewPager.setAdapter(new MainPagerAdapter(getSupportFragmentManager()));
    viewPager.setOffscreenPageLimit(2);

    final NavigationTabStrip navigationTabStrip = (NavigationTabStrip) findViewById(R.id.nts);
    navigationTabStrip.setTitles("HOW WE WORK", "WE WORK WITH");
    navigationTabStrip.setViewPager(viewPager);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:MainActivity.java

示例15: ViewHolder

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
public ViewHolder(View itemView) {
    super(itemView);
    subjectButton = (Button) itemView.findViewById(R.id.subject_button);
    viewPager = (ViewPager) itemView.findViewById(R.id.subject_view_pager);
    viewPager.setOffscreenPageLimit(3);
    adapter = new ImageButtonAdpter(null);
    viewPager.setAdapter(adapter);
}
 
开发者ID:KnowledgeBegger,项目名称:MyEyepetizer,代码行数:9,代码来源:FoundCategorySubjectItemBinder.java


注:本文中的android.support.v4.view.ViewPager.setOffscreenPageLimit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。