Android 操作栏选项卡内的滑动选项卡

Android 操作栏选项卡内的滑动选项卡,android,android-viewpager,flipboard,android-actionbar-tabs,Android,Android Viewpager,Flipboard,Android Actionbar Tabs,我尝试在actionBar选项卡中实现滑动选项卡,就像flipboard一样。因此,其中一个主选项卡将有三个选项卡。子选项卡将首先滚动,一旦所有选项卡被滚动,然后主选项卡进入焦点并开始滚动 我正在附上flipBoard UI的屏幕截图 有人这样做过吗?请提供帮助。它似乎已经由Android管理:您只需要在外部活动中创建一个ViewPager,对于ViewPager托管的每个片段,您都创建一个ViewPager。这是我的测试项目: MainActivity.java public class Ma

我尝试在actionBar选项卡中实现滑动选项卡,就像flipboard一样。因此,其中一个主选项卡将有三个选项卡。子选项卡将首先滚动,一旦所有选项卡被滚动,然后主选项卡进入焦点并开始滚动

我正在附上flipBoard UI的屏幕截图


有人这样做过吗?请提供帮助。

它似乎已经由Android管理:您只需要在外部活动中创建一个ViewPager,对于ViewPager托管的每个片段,您都创建一个ViewPager。这是我的测试项目:

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>
及其布局片段_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>
及其布局片段_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>

就这样!试着让我知道

编辑:
忘了说第一个组件不是ActionBar

谢谢大家。@MimmoGrottoli知道flipboard如何改变viewpager上的文本颜色吗?我想他们有一个透明的图像作为文本,他们移动了一个红色的矩形,放在选项卡下,或者文本的颜色只是透明的:)你可以删除动作栏并添加你的服装控件,比如pager,Tab view。Tab-1=>t11,t12,t13 Tab2=>t21,t22,t23和Tab-3=>t31,t32,t33诸如此类。
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;
    }
}
<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>