Maybe some kind of library is there? or is it all fragments? 
- Are you interested in the indicator above? - post_zeew
- Yes, when you press (or when you swipe), go to other layouts and move the buttons (which screen is the button attached to it by the center) - Sergo
- Do not need links. At least just show the picture, explain with words what is on it and correct the title. - Yuriy SPb ♦
|
1 answer
For swipes between fragments, use ViewPager. To him in the adapter let the fragments you need rejoice! Below is the code for a basic solution.
Create a layout with the viewpager:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v4.view.ViewPager android:id="@+id/vpPager" android:layout_width="match_parent" android:layout_height="wrap_content"> </android.support.v4.view.ViewPager> </LinearLayout> After that, we create several fragments that will actually be in our viewpager. The next step is to create an adapter and assign it to our viewpager:
public static class MyPagerAdapter extends FragmentPagerAdapter { private static int NUM_ITEMS = 3; public MyPagerAdapter(FragmentManager fragmentManager) { super(fragmentManager); } // Возвращает общее количество фрагментов @Override public int getCount() { return NUM_ITEMS; } // Возвращает фрамгент, который будет отображаться сейчас @Override public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 - This will show FirstFragment return FirstFragment.newInstance(0, "Page # 1"); case 1: // Fragment # 0 - This will show FirstFragment different title return FirstFragment.newInstance(1, "Page # 2"); case 2: // Fragment # 1 - This will show SecondFragment return SecondFragment.newInstance(2, "Page # 3"); default: return null; } } // Возвращает заголовок (например, если используете TabLayout) @Override public CharSequence getPageTitle(int position) { return "Page " + position; } } Well, after that, we assign our adapter to our viewpager in the activation code:
... ViewPager vpPager = (ViewPager) findViewById(R.id.vpPager); adapterViewPager = new MyPagerAdapter(getSupportFragmentManager()); vpPager.setAdapter(adapterViewPager); ... - The author asked about the indicator. - post_zeew
- Then just use tabLayout in addition, as I wrote. This is literally a couple of lines and that's it. - Artem Komar
|