Java Code Examples for android.support.v4.view.ViewPager#setId()

The following examples show how to use android.support.v4.view.ViewPager#setId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StickHeaderViewPager.java    From StickyHeaderViewPager with Apache License 2.0 6 votes vote down vote up
public StickHeaderViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.mContext = context;

    // add viewpager
    mViewPager = new ViewPager(context);
    mViewPager.setId(ID_VIEWPAGER);
    addView(mViewPager, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    // add stickheader
    mStickheader = new LinearLayout(context);
    mStickheader.setOrientation(LinearLayout.VERTICAL);
    addView(mStickheader, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    mViewPager.addOnPageChangeListener(this);
}
 
Example 2
Source File: ActionBarTabsPager.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText("Simple"),
            CountingFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("List"),
            FragmentPagerSupport.ArrayListFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Cursor"),
            CursorFragment.class, null);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }
}
 
Example 3
Source File: FragmentNestingStatePagerSupport.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText("Simple"),
            CountingFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("List"),
            FragmentPagerSupport.ArrayListFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Cursor"),
            CursorFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Tabs"),
            FragmentTabsFragment.class, null);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }
}
 
Example 4
Source File: FragmentNestingPagerSupport.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText("Simple"),
            CountingFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("List"),
            FragmentPagerSupport.ArrayListFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Cursor"),
            CursorFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Tabs"),
            FragmentTabsFragment.class, null);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }
}
 
Example 5
Source File: ParallaxContainer.java    From ParallaxSplash with Apache License 2.0 5 votes vote down vote up
/**
 * 指定引导页的所有页面布局文件
 *
 * @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);


}
 
Example 6
Source File: HelpActivity.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      popup(this);
      mPager = new ViewPager(this);
      mPager.setId(R.id.pager);
      setContentView(mPager);
      
      // Set up our ActionBar
      final ActionBar mAB = getActionBar();
      if (null != mAB) {
          // Create a Spannable for a custom font face in the title.
          SpannableString title = new SpannableString(getString(R.string.welcome_to));
          title.setSpan(new TypefaceSpan(this, "TimeBurner_Regular.ttf"), 0, title.length(),
                  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

          mAB.setTitle(title);
          mAB.setDisplayShowTitleEnabled(true);
          mAB.setDisplayHomeAsUpEnabled(true);
      }

// Set our Adapter for the Pager.
      mAdapter = new HelpFragmentAdapter(this);
      mPager.setAdapter(mAdapter);
      
      // We have to add the listener here, because CirclePageIndicator
      // uses the default listener to know when to change state.
      mPager.setOnPageChangeListener(this);
      
      // Save the last/ current item.
      if (savedInstanceState != null && savedInstanceState.containsKey(KEY_POSITION)) {
      	mPager.setCurrentItem(savedInstanceState.getInt(KEY_POSITION));
      }
  }
 
Example 7
Source File: HelpActivity.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      popup(this);
      mPager = new ViewPager(this);
      mPager.setId(R.id.pager);
      setContentView(mPager);
      
      // Set up our ActionBar
      final ActionBar mAB = getActionBar();
      if (null != mAB) {
          // Create a Spannable for a custom font face in the title.
          SpannableString title = new SpannableString(getString(R.string.welcome_to));
          title.setSpan(new TypefaceSpan(this, "TimeBurner_Regular.ttf"), 0, title.length(),
                  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

          mAB.setTitle(title);
          mAB.setDisplayShowTitleEnabled(true);
          mAB.setDisplayHomeAsUpEnabled(true);
      }

// Set our Adapter for the Pager.
      mAdapter = new HelpFragmentAdapter(this);
      mPager.setAdapter(mAdapter);
      
      // We have to add the listener here, because CirclePageIndicator
      // uses the default listener to know when to change state.
      mPager.setOnPageChangeListener(this);
      
      // Save the last/ current item.
      if (savedInstanceState != null && savedInstanceState.containsKey(KEY_POSITION)) {
      	mPager.setCurrentItem(savedInstanceState.getInt(KEY_POSITION));
      }
  }
 
Example 8
Source File: ParallaxContainer.java    From ParallaxPager with MIT License 5 votes vote down vote up
public void setupChildren(LayoutInflater inflater, int... childIds) {
  if (getChildCount() > 0) {
    throw new RuntimeException(
        "setupChildren should only be called once when ParallaxContainer is empty");
  }

  if (childIds.length == 1) {
    int id = childIds[0];
    childIds = new int[2];
    childIds[0] = id;
    childIds[1] = id;
  }

  for (int childId : childIds) {
    inflater.inflate(childId, this);
  }

  // hold pageCount because it will change after we add viewpager
  pageCount = getChildCount();
  for (int i = 0; i < pageCount; i++) {
    View view = getChildAt(i);
    addParallaxView(view, i);
  }

  updateAdapterCount();

  // make view pager with same attributes as container
  viewPager = new ViewPager(getContext());
  viewPager.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
  viewPager.setId(R.id.parallax_pager);
  viewPager.setAdapter(adapter);
  attachOnPageChangeListener(viewPager, this);

  addView(viewPager, 0);
}
 
Example 9
Source File: AbsGuideActivity.java    From guideshow with MIT License 5 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    List<SinglePage> guideContent = buildGuideContent();

    if (guideContent == null) {
        // nothing to show
        return;
    }

    // prepare views
    FrameLayout container = new FrameLayout(this);
    ViewPager pager = new ViewPager(this);
    pager.setId(getPagerId());

    container.addView(pager, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    setContentView(container);

    FragmentPagerAdapter adapter = new FragmentTabAdapter(this, guideContent);
    pager.setAdapter(adapter);

    GuideView guideView = new GuideView(this, guideContent, drawDot(), dotDefault(), dotSelected());
    pager.setOnPageChangeListener(guideView);

    container.addView(guideView, new LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT));
}
 
Example 10
Source File: PullToRefreshViewPager.java    From AndroidBase with Apache License 2.0 4 votes vote down vote up
@Override
protected ViewPager createRefreshableView(Context context, AttributeSet attrs) {
	ViewPager viewPager = new ViewPager(context, attrs);
	viewPager.setId(R.id.viewpager);
	return viewPager;
}
 
Example 11
Source File: LoopViewPagerLayout.java    From LoopViewPagerLayout with MIT License 4 votes vote down vote up
/**
 * Be sure to initialize the View
 */
private void initializeView() {
    L.e("LoopViewPager ---> initializeView");
    float density = getResources().getDisplayMetrics().density;

    loopViewPager = new ViewPager(getContext());
    loopViewPager.setId(R.id.loop_viewpager);
    LayoutParams loop_params = new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    addView(loopViewPager, loop_params);

    // FrameLayout
    FrameLayout indicatorFrameLayout = new FrameLayout(getContext());
    LayoutParams f_params = new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, ((int) (20 * density)));
    f_params.addRule(RelativeLayout.CENTER_HORIZONTAL);//android:layout_centerHorizontal="true"
    f_params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);//android:layout_alignParentBottom="true"

    switch (indicatorLocation) {
        case Left:
            f_params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);// android:layout_alignParentLeft="true"
            break;
        case Right:
            f_params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);//android:layout_alignParentRight="true"
            break;
        default:
            break;
    }

    f_params.setMargins(((int) (10 * density)), 0, ((int) (10 * density)), 0);
    addView(indicatorFrameLayout, f_params);

    // 指标的布局
    indicatorLayout = new LinearLayout(getContext());
    FrameLayout.LayoutParams ind_params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.MATCH_PARENT);
    indicatorLayout.setGravity(Gravity.CENTER);
    indicatorLayout.setOrientation(LinearLayout.HORIZONTAL);
    indicatorFrameLayout.addView(indicatorLayout, ind_params);

    // 动画指标布局
    animIndicatorLayout = new LinearLayout(getContext());
    FrameLayout.LayoutParams ind_params2 = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    animIndicatorLayout.setGravity(Gravity.CENTER | Gravity.START);
    animIndicatorLayout.setOrientation(LinearLayout.HORIZONTAL);
    indicatorFrameLayout.addView(animIndicatorLayout, ind_params2);
}
 
Example 12
Source File: PullToRefreshViewPager.java    From ONE-Unofficial with Apache License 2.0 4 votes vote down vote up
@Override
protected ViewPager createRefreshableView(Context context, AttributeSet attrs) {
    ViewPager viewPager = new ViewPager(context, attrs);
    viewPager.setId(R.id.viewpager);
    return viewPager;
}