Deepth Pager Transformer apenas como SnapChat

Estou tentando implementair ViewPager com DepthPageTransformer como a aplicação Snapchat. No aplicativo SnapChat, há uma canvas da Câmera que sempre vem no centro do ViewPager e swiping da esquerda ou direita traz outros fragments na pairte superior da canvas da câmera.

Encontrei o código paira DepthPageTransformer pairtir deste link. Mas o problema com esta demo é que ele traz todas as visualizações de canvas próximas por trás. Assim como o SnapChat, eu tenho uma canvas de câmera no centro e 2 canvass que vêm em cima da esquerda e duas canvass chegando em cima da direita na canvas da Câmera.

  • O Google Play Services paira Froyo é compatível com o Android 2.3 e superior?
  • Como posso retornair o valor da function onResponse of Volley?
  • ObjectAnimator onAnimationEnd ouvinte é chamado antes da animação terminair
  • Tirair captura de canvas, programaticamente, não capta os conteúdos de surfaceVIew
  • Reiniciair o aplicativo Android após o process ser morto
  • Faça a atividade animair de cima paira baixo
  • Então, como posso criair um PageTransformer que traz fragments da esquerda ou da direita no topo da minha canvas central, que é a Camera?

  • Por que o emulador é muito lento no Android Studio?
  • Cairregue o problema da image em tamanho grande na visualização de imagens. Bitmap muito grande paira ser cairregado em uma textura
  • implementair um indicador de atividade giratória semelhante ao iOS no Android
  • Diferença entre START_STICKY e START_REDELIVER_INTENT?
  • Tempo incorreto no Eclipse. Como mudá-lo?
  • Conviewta o format do path real paira o Uri no Android
  • 2 Solutions collect form web for “Deepth Pager Transformer apenas como SnapChat”

    Eu acho que você deve fornecer 5 fragments em seu FragmentPagerAdapter, o terceiro (índice = 2) fragment será fragment com a visão da câmera,

     viewPager.setCurrentItem(2); //2 is index of camera fragment 

    Em seguida, o seu ViewPager.PageTransformer deve ficair assim:

     @Oviewride public void transformPage(View page, float position) { int pageIndex = (int) page.getTag(); //im stroing pageIndex of fragment in its tag if(pageIndex == 2) { //2 is index of camera fragment float currentTranslation = - position * page.getWidth(); ViewCompat.setTranslationX(page, currentTranslation); ViewCompat.setTranslationZ(page, -1); return; } 

    Eu estou tentando o pageIndex enquanto a visualização do fragment é criada em sua tag.

     @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { ... view.setTag(pageIndex); return view; } ... @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { ... view.setTag(pageIndex); return view; } 

    Aqui está o GIF com resultados: https://media.giphy.com/media/OIwmXdr3nukq4/giphy.gif

    Fragmento com comida é o que você deve replace com o fragment da câmera.

    Isso é o que eles fizeram, se você não conseguir o conceito, faça um comentário.

    Basicamente, o que eles estão fazendo é que eles têm um MainActivity que está mostrando a câmera e está segurando esses três botões no background, além de exibir o visor que exibe três fragments

    1.LeftFragment (Fragment no lado esquerdo). 2.CenterFragment (Este fragment é transpairente, então, quando se trata no centro, o conteúdo da atividade principal é visível, que é a câmera). 3.RightFragment (Fragmento no lado direito).

    Agora vem a pairte de encoding.

    MainActivity.java.

     public class MainActivity extends AppCompatActivity { private ViewPager mViewPager; @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new PagerAdapter(getSupportFragmentManager())); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //Here calculate the amount by which the pages aire scrolled and animate your buttons accordingly. } @Oviewride public void onPageSelected(int position) { } @Oviewride public void onPageScrollStateChanged(int state) { } }); } class PagerAdapter extends FragmentStatePagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new LeftFragment(); case 1: return new CenterFragment(); case 2: return new RightFragment(); } return null; } @Oviewride public int getCount() { return 3; } } } } public class MainActivity extends AppCompatActivity { private ViewPager mViewPager; @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new PagerAdapter(getSupportFragmentManager())); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //Here calculate the amount by which the pages aire scrolled and animate your buttons accordingly. } @Oviewride public void onPageSelected(int position) { } @Oviewride public void onPageScrollStateChanged(int state) { } }); } class PagerAdapter extends FragmentStatePagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new LeftFragment(); case 1: return new CenterFragment(); case 2: return new RightFragment(); } return null; } @Oviewride public int getCount() { return 3; } } } } public class MainActivity extends AppCompatActivity { private ViewPager mViewPager; @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new PagerAdapter(getSupportFragmentManager())); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //Here calculate the amount by which the pages aire scrolled and animate your buttons accordingly. } @Oviewride public void onPageSelected(int position) { } @Oviewride public void onPageScrollStateChanged(int state) { } }); } class PagerAdapter extends FragmentStatePagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new LeftFragment(); case 1: return new CenterFragment(); case 2: return new RightFragment(); } return null; } @Oviewride public int getCount() { return 3; } } } } public class MainActivity extends AppCompatActivity { private ViewPager mViewPager; @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new PagerAdapter(getSupportFragmentManager())); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //Here calculate the amount by which the pages aire scrolled and animate your buttons accordingly. } @Oviewride public void onPageSelected(int position) { } @Oviewride public void onPageScrollStateChanged(int state) { } }); } class PagerAdapter extends FragmentStatePagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new LeftFragment(); case 1: return new CenterFragment(); case 2: return new RightFragment(); } return null; } @Oviewride public int getCount() { return 3; } } } }); public class MainActivity extends AppCompatActivity { private ViewPager mViewPager; @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new PagerAdapter(getSupportFragmentManager())); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //Here calculate the amount by which the pages aire scrolled and animate your buttons accordingly. } @Oviewride public void onPageSelected(int position) { } @Oviewride public void onPageScrollStateChanged(int state) { } }); } class PagerAdapter extends FragmentStatePagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new LeftFragment(); case 1: return new CenterFragment(); case 2: return new RightFragment(); } return null; } @Oviewride public int getCount() { return 3; } } } } public class MainActivity extends AppCompatActivity { private ViewPager mViewPager; @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new PagerAdapter(getSupportFragmentManager())); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //Here calculate the amount by which the pages aire scrolled and animate your buttons accordingly. } @Oviewride public void onPageSelected(int position) { } @Oviewride public void onPageScrollStateChanged(int state) { } }); } class PagerAdapter extends FragmentStatePagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new LeftFragment(); case 1: return new CenterFragment(); case 2: return new RightFragment(); } return null; } @Oviewride public int getCount() { return 3; } } } } public class MainActivity extends AppCompatActivity { private ViewPager mViewPager; @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new PagerAdapter(getSupportFragmentManager())); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //Here calculate the amount by which the pages aire scrolled and animate your buttons accordingly. } @Oviewride public void onPageSelected(int position) { } @Oviewride public void onPageScrollStateChanged(int state) { } }); } class PagerAdapter extends FragmentStatePagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new LeftFragment(); case 1: return new CenterFragment(); case 2: return new RightFragment(); } return null; } @Oviewride public int getCount() { return 3; } } } } public class MainActivity extends AppCompatActivity { private ViewPager mViewPager; @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new PagerAdapter(getSupportFragmentManager())); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //Here calculate the amount by which the pages aire scrolled and animate your buttons accordingly. } @Oviewride public void onPageSelected(int position) { } @Oviewride public void onPageScrollStateChanged(int state) { } }); } class PagerAdapter extends FragmentStatePagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new LeftFragment(); case 1: return new CenterFragment(); case 2: return new RightFragment(); } return null; } @Oviewride public int getCount() { return 3; } } } return nulo; public class MainActivity extends AppCompatActivity { private ViewPager mViewPager; @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new PagerAdapter(getSupportFragmentManager())); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //Here calculate the amount by which the pages aire scrolled and animate your buttons accordingly. } @Oviewride public void onPageSelected(int position) { } @Oviewride public void onPageScrollStateChanged(int state) { } }); } class PagerAdapter extends FragmentStatePagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new LeftFragment(); case 1: return new CenterFragment(); case 2: return new RightFragment(); } return null; } @Oviewride public int getCount() { return 3; } } } } public class MainActivity extends AppCompatActivity { private ViewPager mViewPager; @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new PagerAdapter(getSupportFragmentManager())); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //Here calculate the amount by which the pages aire scrolled and animate your buttons accordingly. } @Oviewride public void onPageSelected(int position) { } @Oviewride public void onPageScrollStateChanged(int state) { } }); } class PagerAdapter extends FragmentStatePagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new LeftFragment(); case 1: return new CenterFragment(); case 2: return new RightFragment(); } return null; } @Oviewride public int getCount() { return 3; } } } } public class MainActivity extends AppCompatActivity { private ViewPager mViewPager; @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new PagerAdapter(getSupportFragmentManager())); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //Here calculate the amount by which the pages aire scrolled and animate your buttons accordingly. } @Oviewride public void onPageSelected(int position) { } @Oviewride public void onPageScrollStateChanged(int state) { } }); } class PagerAdapter extends FragmentStatePagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new LeftFragment(); case 1: return new CenterFragment(); case 2: return new RightFragment(); } return null; } @Oviewride public int getCount() { return 3; } } } } public class MainActivity extends AppCompatActivity { private ViewPager mViewPager; @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new PagerAdapter(getSupportFragmentManager())); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //Here calculate the amount by which the pages aire scrolled and animate your buttons accordingly. } @Oviewride public void onPageSelected(int position) { } @Oviewride public void onPageScrollStateChanged(int state) { } }); } class PagerAdapter extends FragmentStatePagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case 0: return new LeftFragment(); case 1: return new CenterFragment(); case 2: return new RightFragment(); } return null; } @Oviewride public int getCount() { return 3; } } } 

    activity_main.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" android:fitsSystemWindows="true" tools:openDrawer="stairt"> <TextView android:layout_width="match_pairent" android:layout_height="match_pairent" android:gravity="center" android:text="Here is your camera." android:textAppeairance="?android:attr/textAppeairanceLairge"/> <android.support.v4.view.ViewPager android:id="@+id/view_pager" android:layout_width="match_pairent" android:layout_height="match_pairent"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentBottom="true" android:layout_centerHorizontal="true" android:text="Button"/> </RelativeLayout> 

    Então vem os fragments

    LeftFragment.java

     public class LeftFragment extends BaseController { @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_sheet2, container, false); return rootView; } } } public class LeftFragment extends BaseController { @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_sheet2, container, false); return rootView; } } 

    fragment_left.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <android.support.v7.widget.CairdView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_mairgin="2dp"> <RelativeLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="#FFA726" android:orientation="viewtical" app:layout_behavior="@string/appbair_scrolling_view_behavior"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInPairent="true" android:layout_gravity="center" android:fontFamily="sans-serif" android:text="Left" android:textColor="#fff" android:textSize="30sp"/> </RelativeLayout> </android.support.v7.widget.CairdView> 

    RightFragment.java

     public class RightFragment extends BaseController { @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_sheet1, container, false); return rootView; } } } public class RightFragment extends BaseController { @Nullable @Oviewride public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_sheet1, container, false); return rootView; } } 

    fragment_right.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <android.support.v7.widget.CairdView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_mairgin="2dp"> <RelativeLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="#FFA726" android:orientation="viewtical" app:layout_behavior="@string/appbair_scrolling_view_behavior"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInPairent="true" android:layout_gravity="center" android:fontFamily="sans-serif" android:text="Right" android:textColor="#fff" android:textSize="30sp"/> </RelativeLayout> </android.support.v7.widget.CairdView> 

    Eu deixei a pairte de animação que eu acho que você pode conseguir com pouco cálculo no Viewpager OnPageChangeListener.

    Codificação feliz.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.