Google has finally released its rolling api tabs.
To use SlidingTabsBasic, you first need to download the zip file from: http://developer.android.com/downloads/samples/SlidingTabsBasic.zip
- Include the 2 java source files in the com.example.android.common.view package in your project. You can move them to a suitable package in your project.
- To use a component, simply add it to your view hierarchy. Then, in your activity or fragment, provide SlidingTabsBasic with your viewPager by calling mSlidingTabLayout.setViewPager (mViewPager);
Google Layout Example:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.example.android.common.view.SlidingTabLayout android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:layout_height="wrap_content" /> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="0px" android:layout_weight="1" android:background="@android:color/white"/> </LinearLayout>
Example code in the onCreate () method of your activity:
mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs); mSlidingTabLayout.setViewPager(mViewPager);
For more details see the example in the zip file SlidingTabsBasicFragment.java and fragment_sample.xml
Tianhai Feb 22 '14 at 9:51 2014-02-22 09:51
source share