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