Implementing JazzyViewPager

大兔子大兔子 提交于 2019-12-25 07:00:06

问题


Branching from my other question from HERE, I want to try and implement JazzyViewPager. I tried following the setup instructions along with a few other posts on this site, but was unable to get it working, just did the ViewPager action.

Below is the relevant untouched (sync issue with AIDE erased previous) code I'm working with.

MainActivity:

pageAdapter = new MyPagerAdapter(getSupportFragmentManager());
final ViewPager pager = (ViewPager) findViewById(R.id.myViewPager);
pager.setAdapter(pageAdapter);
pager.setOffscreenPageLimit(1);
pager.setPageMarginDrawable(R.color.pager_bg);

MyPagerAdapter:

package com.chris.myapp;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import com.chris.myapp.fragment.Shoutbox;
import com.chris.myapp.fragment.WebViewFragment;

import java.util.ArrayList;
import java.util.List;

public class MyPagerAdapter extends FragmentPagerAdapter {
    public static final int WEBVIEW_FRAGMENT_POSITION = 0;
    public static final int SHOUTBOX_FRAGMENT_POSITION = 1;

    private List<Fragment> fragments;

    public MyPagerAdapter(FragmentManager fm) {
        super(fm);

        this.fragments = new ArrayList<Fragment>();
        fragments.add(new WebViewFragment());
        fragments.add(new Shoutbox());
    }

    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    public int getCount() {
        return fragments.size();
    }
}

Content.xml

<android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/myViewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#111" />

Any help would be greatly appreciated.


回答1:


You can get the package libraries here

You content xml should be:

<packagename.JazzyViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/myViewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#111" />

You call the MainAdapter class to initialize the object and your various screens by:

JazzyViewPager mPager = (JazzyViewPager)findViewById(R.id.pager);
mPager.setAdapter(new MainAdapter());

Various transition effects are available like:

public enum TransitionEffect {
    Standard,
    Tablet,
    CubeIn,
    CubeOut,
    Flip,
    Stack,
    ZoomIn,
    ZoomOut,
    RotateUp,
    RotateDown,
    Accordion
}

All these animations are placed in the JazzyViewPager class and you can call any one of the above mentioned animations by:

mPager.setTransitionEffect(TransitionEffect.*);

I hope the answer helps. I you still are unable to do it then i can post the code by which i have implemented the JazzyViewPager.



来源:https://stackoverflow.com/questions/21103886/implementing-jazzyviewpager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!