"Android Interface Implementation" uses Pagerslidingtabstrip to realize the Viewpager effect of sliding label synchronization

Source: Internet
Author: User

Reprint Please specify Source: http://blog.csdn.net/zhaokaiqiang1992

There are three previous articles that show how to add an indicator to Viewpager, and this is the last article to introduce an indicator of viewpager.

This article describes the use of open source project Pagerslidingtabstrip to achieve this effect. This open source project is the same author as the previous scrpllingtabs.

Let's look at the effect of the implementation first.



The difference between this implementation and the previous one is that the color label at the bottom will move in sync with the Viewpager, which is more vivid than the previous implementation.

In addition, code writing is basically the same as scrollingtabs.

The first is the layout file.

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:app= "http// Schemas.android.com/apk/res-auto "    xmlns:tools=" Http://schemas.android.com/tools "    android:layout_width= "Match_parent"    android:layout_height= "match_parent" >    <com.astuetz.pagerslidingtabstrip        Android:id= "@+id/tabs"        android:layout_width= "match_parent"        android:layout_height= "48dip"        android: background= "@drawable/background_tabs"/>    <android.support.v4.view.viewpager        android:id= "@+id/ Pager "        android:layout_width=" match_parent "        android:layout_height=" wrap_content "        android:layout_ Above= "@+id/colors"        android:layout_below= "@+id/tabs"        tools:context= ". Mainactivity "/></relativelayout>

in the activity, the adapter will be set.

@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main) tabs = (Pagerslidingtabstrip) Findviewbyid (r.id.tabs);p ager = (Viewpager) findViewById ( R.id.pager) adapter = new Mypageradapter (Getsupportfragmentmanager ());p Ager.setadapter (adapter); Tabs.setviewpager (pager);}

Adapter for Viewpager

public class Mypageradapter extends Fragmentpageradapter {private final string[] TITLES = {"Categories", "Home", "Top Pai D "," Top Free "," Top Grossing "," Top New Paid "," Top New free "," trending "};p ublic Mypageradapter (fragmentmanager FM) {SUP ER (FM);} @Overridepublic charsequence getpagetitle (int position) {return titles[position];} @Overridepublic int GetCount () {return titles.length;} @Overridepublic Fragment getItem (int position) {return superawesomecardfragment.newinstance (position);}}

GitHub Project Address: Https://github.com/astuetz/PagerSlidingTabStrip

"Android Interface Implementation" uses Pagerslidingtabstrip to realize the Viewpager effect of sliding label synchronization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.