Java Code Examples for androidx.viewpager.widget.ViewPager#setPageTransformer()

The following examples show how to use androidx.viewpager.widget.ViewPager#setPageTransformer() . 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: VPAnim2Activity.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_vpanim2);
        initDatas();
//        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.setPageMargin(20);
        mViewPager.setAdapter(mSectionsPagerAdapter);
        mViewPager.setOffscreenPageLimit(3);
        mViewPager.setPageTransformer(true, new MyTranformer());
    }
 
Example 2
Source File: VPAnimActivity.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_vpanim);
        initDatas();
        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);
        mViewPager.setPageTransformer(true, new DepthPageTransformer());


        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(mContext, VPAnim2Activity.class));
//                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
//                        .setAction("Action", null).show();
            }
        });

    }
 
Example 3
Source File: MyGuildView.java    From Ruisi with Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    this.context = context;
    dotMargine = DimenUtils.dip2px(context, 2);
    containerPaddingTB = DimenUtils.dip2px(context, 8);
    containerPaddingLR = DimenUtils.dip2px(context, 12);

    dotImageResourseId = R.drawable.dot_bg;
    viewPager = new ViewPager(context);
    viewPager.setLayoutParams(new LayoutParams(RMP, RMP));
    viewPager.addOnPageChangeListener(this);
    adapter = new PageAdapter();
    viewPager.setPageTransformer(true, new ScalePageTransformer());
    viewPager.setAdapter(adapter);
    addView(viewPager);

    dotContainer = new LinearLayout(context);
    LayoutParams lp = new LayoutParams(RMP, RWC);
    lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    // 在这儿设置圆点位置
    lp.addRule(CENTER_HORIZONTAL);
    dotContainer.setLayoutParams(lp);
    dotContainer.setOrientation(LinearLayout.HORIZONTAL);
    //dotContainer.setGravity(CENTER_HORIZONTAL);
    dotContainer.setGravity(CENTER_VERTICAL);
    dotContainer.setBackgroundColor(0x7f333333);
    dotContainer.setPadding(containerPaddingLR, containerPaddingTB, containerPaddingLR, containerPaddingTB);
    addView(dotContainer);

    mAutoPlayTask = new AutoPlayTask(this);
}
 
Example 4
Source File: EmojiView.java    From Emoji with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("PMD.CyclomaticComplexity") public EmojiView(final Context context,
    final OnEmojiClickListener onEmojiClickListener,
    final OnEmojiLongClickListener onEmojiLongClickListener, @NonNull final EmojiPopup.Builder builder) {
  super(context);

  View.inflate(context, R.layout.emoji_view, this);

  setOrientation(VERTICAL);
  setBackgroundColor(builder.backgroundColor != 0 ? builder.backgroundColor : Utils.resolveColor(context, R.attr.emojiBackground, R.color.emoji_background));
  themeIconColor = builder.iconColor != 0 ? builder.iconColor : Utils.resolveColor(context, R.attr.emojiIcons, R.color.emoji_icons);

  final TypedValue value = new TypedValue();
  context.getTheme().resolveAttribute(R.attr.colorAccent, value, true);
  themeAccentColor = builder.selectedIconColor != 0 ? builder.selectedIconColor : value.data;

  final ViewPager emojisPager = findViewById(R.id.emojiViewPager);
  final View emojiDivider = findViewById(R.id.emojiViewDivider);
  emojiDivider.setBackgroundColor(builder.dividerColor != 0 ? builder.dividerColor : Utils.resolveColor(context, R.attr.emojiDivider, R.color.emoji_divider));

  if (builder.pageTransformer != null) {
    emojisPager.setPageTransformer(true, builder.pageTransformer);
  }

  final LinearLayout emojisTab = findViewById(R.id.emojiViewTab);
  emojisPager.addOnPageChangeListener(this);

  final EmojiCategory[] categories = EmojiManager.getInstance().getCategories();

  emojiTabs = new ImageButton[categories.length + 2];
  emojiTabs[0] = inflateButton(context, R.drawable.emoji_recent, R.string.emoji_category_recent, emojisTab);
  for (int i = 0; i < categories.length; i++) {
    emojiTabs[i + 1] = inflateButton(context, categories[i].getIcon(), categories[i].getCategoryName(), emojisTab);
  }
  emojiTabs[emojiTabs.length - 1] = inflateButton(context, R.drawable.emoji_backspace, R.string.emoji_backspace, emojisTab);

  handleOnClicks(emojisPager);

  emojiPagerAdapter = new EmojiPagerAdapter(onEmojiClickListener, onEmojiLongClickListener, builder.recentEmoji, builder.variantEmoji);
  emojisPager.setAdapter(emojiPagerAdapter);

  final int startIndex = emojiPagerAdapter.numberOfRecentEmojis() > 0 ? 0 : 1;
  emojisPager.setCurrentItem(startIndex);
  onPageSelected(startIndex);
}