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


Java ViewPager类代码示例

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


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

示例1: setUpViewPager

import android.support.v4.view.ViewPager; //导入依赖的package包/类
private void setUpViewPager(ArrayList<Photo> photos) {
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(new DetailViewPagerAdapter(this, photos, sharedElementCallback));
    viewPager.setCurrentItem(initialItem);

    viewPager.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                                   int oldLeft, int oldTop, int oldRight, int oldBottom) {
            if (viewPager.getChildCount() > 0) {
                viewPager.removeOnLayoutChangeListener(this);
                startPostponedEnterTransition();
            }
        }
    });

    viewPager.setPageMargin(getResources().getDimensionPixelSize(
            com.example.android.unsplash.base.R.dimen.padding_mini));
    viewPager.setPageMarginDrawable(R.drawable.page_margin);
}
 
开发者ID:googlesamples,项目名称:android-instant-apps,代码行数:21,代码来源:DetailActivity.java

示例2: onCreate

import android.support.v4.view.ViewPager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);

    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
    setTabLayoutListener();
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    initTabIcons();
    //default position
    viewPager.setCurrentItem(1);
}
 
开发者ID:oantajames,项目名称:mdb-android-application,代码行数:17,代码来源:MoviesGridActivity.java

示例3: onCreate

import android.support.v4.view.ViewPager; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.fade_in,R.anim.fade_out);
    // Set title for the ViewPager
    setTitle("ViewPager");
    // Get the view from view_pager.xml
    setContentView(R.layout.view_pager);

    // Retrieve data from MainActivity on item click event
    Intent p = getIntent();
    position = p.getExtras().getInt("id");

    ImageAdapter imageAdapter = new ImageAdapter(this);
    List<ImageView> images = new ArrayList<ImageView>();

    // Retrieve all the images
    for (int i = 0; i < imageAdapter.getCount(); i++) {
        ImageView imageView = new ImageView(this);
        //imageView.setImageResource(imageAdapter.mThumbIds[i]);
            Picasso.with(this)
                    .load(GalleryFragment.mThumbIds[i])
                    .placeholder(R.drawable.loading)
                    .error(R.drawable.error)
                    .into(imageView);
        imageView.setScaleType(ImageView.ScaleType.CENTER);
        //imageView.setScaleType(ImageView.ScaleType.CENTER);
        images.add(imageView);
    }

    // Set the images into ViewPager
    ImagePagerAdapter pageradapter = new ImagePagerAdapter(images);
    ViewPager viewpager = (ViewPager) findViewById(R.id.pager);
    viewpager.setAdapter(pageradapter);
    viewpager.setPageTransformer(true, new ZoomOutPageTransformer());
    // Show images following the position
    viewpager.setCurrentItem(position);
}
 
开发者ID:Ronak-59,项目名称:Trinity-App,代码行数:39,代码来源:ImageViewPager.java

示例4: onCreate

import android.support.v4.view.ViewPager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    setContentView(R.layout.activity_tutorias);
    //Action bar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().setNavigationBarColor(getResources().getColor(R.color.colorPrimaryDarkGreen));
        getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDarkGreen));
    }
    app = (App) this.getApplication();
    //SetView
    viewPager = (ViewPager) findViewById(R.id.viewpager);
    tabLayout = (TabLayout) findViewById(R.id.tabs);
    progress = (AVLoadingIndicatorView) findViewById(R.id.material_progress);
    title = (TextView) findViewById(R.id.toolbar_title);
    fabTut = (FloatingActionButton) findViewById(R.id.fabTut);
    setYearAdapters();
    request = new TutoriasRequest(this);
    updateYear(true, app.getPublicPreferenceI(Common.GLOBAL_FILTER_YEAR));
    doRequest();
}
 
开发者ID:Onelio,项目名称:ConnectU,代码行数:26,代码来源:TutoriasActivity.java

示例5: onMeasure

import android.support.v4.view.ViewPager; //导入依赖的package包/类
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final ViewPager viewPager = mViewPager;
    measureChild(viewPager, widthMeasureSpec, heightMeasureSpec);

    final int measuredWidthAndState = viewPager.getMeasuredWidthAndState();
    final int measuredHeightAndState = viewPager.getMeasuredHeightAndState();
    setMeasuredDimension(measuredWidthAndState, measuredHeightAndState);

    final int pagerWidth = viewPager.getMeasuredWidth();
    final int pagerHeight = viewPager.getMeasuredHeight();
    final int buttonWidthSpec = MeasureSpec.makeMeasureSpec(pagerWidth, MeasureSpec.AT_MOST);
    final int buttonHeightSpec = MeasureSpec.makeMeasureSpec(pagerHeight, MeasureSpec.AT_MOST);
    mPrevButton.measure(buttonWidthSpec, buttonHeightSpec);
    mNextButton.measure(buttonWidthSpec, buttonHeightSpec);
}
 
开发者ID:Gericop,项目名称:DateTimePicker,代码行数:17,代码来源:DayPickerView.java

示例6: dispatchOnPageScrolled

import android.support.v4.view.ViewPager; //导入依赖的package包/类
private void dispatchOnPageScrolled(int position, float offset, int offsetPixels) {
    int newPosition = isCirculatory ? position % mAdapter.getCount() : position;
    if (mOnPageChangeListener != null) {
        mOnPageChangeListener.onPageScrolled(newPosition, offset, offsetPixels);
    }
    if (mOnPageChangeListeners != null) {
        for (int i = 0, z = mOnPageChangeListeners.size(); i < z; i++) {
            ViewPager.OnPageChangeListener listener = mOnPageChangeListeners.get(i);
            if (listener != null) {
                listener.onPageScrolled(newPosition, offset, offsetPixels);
            }
        }
    }
    if (mInternalPageChangeListener != null) {
        mInternalPageChangeListener.onPageScrolled(newPosition, offset, offsetPixels);
    }
}
 
开发者ID:youngkaaa,项目名称:YViewPagerDemo,代码行数:18,代码来源:YViewPagerNew.java

示例7: setViewPager

import android.support.v4.view.ViewPager; //导入依赖的package包/类
@Override
public void setViewPager(ViewPager viewPager) {
    if (mViewPager == viewPager) {
        return;
    }
    if (mViewPager != null) {
        //Clear us from the old pager.
        mViewPager.setOnPageChangeListener(null);
    }
    if (viewPager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = viewPager;
    mViewPager.setOnPageChangeListener(this);
    invalidate();
    post(new Runnable() {
        @Override public void run() {
            if (mFades) {
                post(mFadeRunnable);
            }
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:UnderlinePageIndicator.java

示例8: onCreate

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

    mViewPager = (ViewPager) findViewById(R.id.view_pager);
    mViewPager.setAdapter(mExamplePagerAdapter);

    initMagicIndicator1();
    initMagicIndicator2();
    initMagicIndicator3();
    initMagicIndicator4();
    initMagicIndicator5();
    initMagicIndicator6();
    initMagicIndicator7();
    initMagicIndicator8();
    initMagicIndicator9();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:ScrollableTabExampleActivity.java

示例9: setViewPager

import android.support.v4.view.ViewPager; //导入依赖的package包/类
@Override
public void setViewPager(ViewPager viewPager) {
    if (mViewPager == viewPager) {
        return;
    }
    if (mViewPager != null) {
        //Clear us from the old pager.
        mViewPager.setOnPageChangeListener(null);
    }
    if (viewPager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = viewPager;
    mViewPager.setOnPageChangeListener(this);
    invalidate();
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:17,代码来源:LinePageIndicator.java

示例10: onCreate

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // 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.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);


    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Aspe", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

}
 
开发者ID:Francescopaolo44,项目名称:AndroidApp-Deploy,代码行数:27,代码来源:EnglishActivity.java

示例11: onCreate

import android.support.v4.view.ViewPager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_postulaciones_activas);
    // Setting ViewPager for each Tabs
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager_pa);
    setupViewPager(viewPager);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerpa);
    // Adding menu icon to Toolbar
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        VectorDrawableCompat indicator
                = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu, getTheme());
        indicator.setTint(ResourcesCompat.getColor(getResources(),R.color.white,getTheme()));
        supportActionBar.setHomeAsUpIndicator(indicator);
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }

}
 
开发者ID:sloiza,项目名称:changApp,代码行数:20,代码来源:PostulacionesActivasActivity.java

示例12: onCreate

import android.support.v4.view.ViewPager; //导入依赖的package包/类
/**
 * Create the tabs and instantiate the social tabs
 * @param savedInstanceState
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_social);
    drawToolbar();

    ViewPager viewPager = (ViewPager) findViewById(R.id.socialPager);
    adapter = new ViewPagerAdapter(getSupportFragmentManager());

    adapter.addFragment(new FollowingFragment(), "Following");
    adapter.addFragment(new FollowersFragment(), "Followers");
    adapter.addFragment(new FollowRequestsFragment(), "Requests");
    adapter.addFragment(new SearchUsersFragment(), "Search");
    viewPager.setAdapter(adapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.socialTabs);
    tabLayout.setupWithViewPager(viewPager);
}
 
开发者ID:CMPUT301F17T13,项目名称:cat-is-a-dog,代码行数:23,代码来源:SocialActivity.java

示例13: onCreateView

import android.support.v4.view.ViewPager; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.simplefragment_viewpaper_fragment_parent, container, false);
    totalfullheight = view.getHeight();
    AppCompatActivity parentActivity = (AppCompatActivity) getActivity();
    mPagerAdapter = new NavigationAdapter(getChildFragmentManager());
    mPager = (ViewPager) view.findViewById(R.id.pager);
    pager_wrapper = (FrameLayout) view.findViewById(R.id.pager_wrapper);
    mPager.setAdapter(mPagerAdapter);
    mHeaderContainer = (View) view.findViewById(R.id.header);
    headerBanner = (ImageView) view.findViewById(R.id.header_background);
    slidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs);
    slidingTabLayout.setCustomTabView(R.layout.tab_indicator, android.R.id.text1);
    slidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.accent));
    slidingTabLayout.setDistributeEvenly(true);
    slidingTabLayout.setViewPager(mPager);
    ViewConfiguration vc = ViewConfiguration.get(parentActivity);
    mSlop = vc.getScaledTouchSlop();
    mInterceptionLayout = (TouchInterceptionLayout) view.findViewById(R.id.container);
    mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener);
    mPager.setCurrentItem(0);
    return view;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ViewPagerTabFragmentParentFragment.java

示例14: hookNavBar

import android.support.v4.view.ViewPager; //导入依赖的package包/类
private static void hookNavBar(ViewGroup rootView, ViewGroup navbarView) {
    rootNavbarView = rootView;
    Context context = rootView.getContext();
    ViewPager vpXpHook = new ViewPager(context);

    exNavbar = new LinearLayout(context);
    musicControllerPanel = new MusicControllerPanel(context);
    onHomeNavbar = new LinearLayout(context);

    initExNavbar(vpXpHook, exNavbar);
    initHomeNavbar(onHomeNavbar, vpXpHook);
    initMusicPanel(musicControllerPanel);
    initVpHook(vpXpHook, navbarView, exNavbar, musicControllerPanel, onHomeNavbar);

    initBroadcast(context);
    initClipBoardListener(context);

    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
            ViewPager.LayoutParams.MATCH_PARENT, ViewPager.LayoutParams.MATCH_PARENT);
    rootView.addView(vpXpHook, 0, params);

    setNavbarHeight(context, DataHook.navbarHeight);
}
 
开发者ID:EggUncle,项目名称:XposedNavigationBar,代码行数:24,代码来源:NavBarHook.java

示例15: findScrollView

import android.support.v4.view.ViewPager; //导入依赖的package包/类
/**
 * Find out the scrollable child view
 * 这里添加了常用的一些可滑动类,特殊类需要添加
 *
 * @param target targetView
 */
private void findScrollView(ViewGroup target) {
    final int count = target.getChildCount();
    if (count > 0) {
        for (int i = 0; i < count; i++) {
            final View child = target.getChildAt(i);
            if (child instanceof AbsListView
                    || isInstanceOfClass(child, ScrollView.class.getName())
                    || isInstanceOfClass(child, NestedScrollView.class.getName())
                    || isInstanceOfClass(child, RecyclerView.class.getName())
                    || child instanceof HorizontalScrollView
                    || child instanceof ViewPager
                    || child instanceof WebView) {
                mScrollChild = child;
                break;
            } else if (child instanceof ViewGroup) {
                findScrollView((ViewGroup) child);
            }
        }
    }
    if (mScrollChild == null) mScrollChild = target;
}
 
开发者ID:zhouphenix,项目名称:Multi-SwipeBackLayout,代码行数:28,代码来源:SwipeBackLayout.java


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