Wygląda na to, że jest już zarządzany przez Androida: wystarczy utworzyć ViewPager w zewnętrznej aktywności i dla każdego fragmentu hostowanego przez ViewPager utworzysz ViewPager. To jest mój projekt badawczy:
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager());
ViewPager viewPager = (ViewPager) findViewById(R.id.pager_activity);
viewPager.setAdapter(adapter);
}
private class MyPagerAdapter extends FragmentStatePagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public android.support.v4.app.Fragment getItem(int i) {
return new InnerFragment();
}
@Override
public int getCount() {
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
return "ACTIVITY TITLE " + (position+1);
}
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager_activity"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:textColor="#fff"
android:paddingTop="4dp"
android:paddingBottom="4dp" />
</android.support.v4.view.ViewPager>
</RelativeLayout>
InnerFragment.java (jednego fragmentu gospodarzem wewnątrz viewpager działalności)
public class InnerFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_inner, container, false);
ViewPager pager = (ViewPager) root.findViewById(R.id.pager);
MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager());
pager.setAdapter(adapter);
return root;
}
private class MyPagerAdapter extends FragmentStatePagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public android.support.v4.app.Fragment getItem(int i) {
return PageFragment.newInstance(i+1);
}
@Override
public int getCount() {
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
return "FRAGMENT " + (position+1) + " TITLE " + (position+1);
}
}
}
i jego układ fragment_inner.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="it.test.testflipboardviewpager.InnerFragment">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:textColor="#fff"
android:paddingTop="4dp"
android:paddingBottom="4dp" />
</android.support.v4.view.ViewPager>
</FrameLayout>
PageFragment.java - jednego fragmentu hostowane przez InnerFragment viewpager
public class PageFragment extends Fragment {
private int mPosition;
public static PageFragment newInstance(int position) {
PageFragment fragment = new PageFragment();
Bundle args = new Bundle();
args.putInt("position", position);
fragment.setArguments(args);
return fragment;
}
public PageFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mPosition = getArguments().getInt("position");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View root = inflater.inflate(R.layout.fragment_page, container, false);
TextView textView = (TextView) root.findViewById(R.id.text);
textView.setText("" + mPosition);
return root;
}
}
i jego układ fragment_page.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="it.test.testflipboardviewpager.PageFragment">
<TextView
android:id="@+id/text"
android:textSize="25sp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
to jest to! Spróbuj i daj mi znać.
Edytuj:Zapomniałem powiedzieć, że pierwszy składnik nie jest paskiem akcji.
Dzięki chłopaki .. @ MimmoGrottoli Każdy pomysł, jak zmienia się kolor tekstu na flipchoku na Viewpager onPageScroll – user1288005
Myślę, że mają przezroczysty obraz jako tekst i przenoszą czerwony prostokąt umieszczony pod kartą –
A może kolor tekstu jest po prostu przezroczysty :) –