當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。