Pagerslidingtabstrip makes Android multi interface sliding switching with labels

Here we use two libraries, one is android-support-v4 in the Android SDK, and the other is pagerslidingtabstrip. The open source project address is https://github.com/astuetz/PagerSlidingTabStrip Using V4 requires its viewpager and fragment, and pagerslidingtabstrip is the label on the application.

Preview of achievements:

Next, start ~ layout

Don't talk about creating an activity. If you like actionbar, you can create an actionbar activity, which requires V7 support package. Here is the layout of this activity:

Com.astuetz.pagerslidingtabstrip these are the tabs at the top of the interface. Here I specify the height of 48dp, which is also the height of the feedback area strongly recommended in Android design. A colleague saw that he used radiogroup to do these tags and added a view to do the active indicator below when he was cooperating to develop the app. It is easy to make mistakes. Needless to say, the code complexity is definitely much higher than what I want to post below. It's not that I'm lazy and don't want to realize it myself, but I think there are so many good things in the world that others have kind intentions to help you finish waiting for you. If I have to twist myself to make a set, it's not worth the loss. Everyone wants to be awesome and want to make something more awesome than others, but I think it's not easy to combine some existing good things perfectly.

Said some irrelevant points and got back to the point. Very simple upper and lower structure layout, needless to say. Android: overscrollmode = "never" in viewpager is a small tip. I don't like the cross-border effect of viewpager (fadingedge = "None" doesn't work). This layout parameter can invalidate the cross-border effect of viewpager.

code

As we all know, the members in viewpager must be fragments, so before configuring viewpager and pagerslidingtabstrip, you need to create a simple fragment to display in viewpager.

After the fragment is created, the comments are written into the code, which is easy to understand and very simple. Below is the activity Code:

Pagerslidingtabstrip this control has many customizable properties, including the color of each label, the color of characters, the drawable of intervals, and so on. If you have needs, you can take a closer look at its GitHub home page and the official sample.

In summary, combined with the open source control pagerslidingtabstrip, we can easily develop multiple interfaces with labels that can slide. In terms of the amount of code, it is very few to tell the truth, and it is logically easy to understand. Without even registering any listener, we have realized the interaction between labels and each interface (click the label switching interface or sliding interface to switch labels), Moreover, the indicator cursor has been designed to slide with the user, saving a lot of development time.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>