Tab interval setting method based on tablayout (example explanation)

The collocation of TabLayout and ViewPager is a lot of convenience, but TabLayout still has many places to make complaints about.

Here we only talk about how to set the interval between tabs. We have found a lot of methods on the Internet. Nothing about padding and margin is useless. There is no way. If you want to use tablayout, you can only find a way by yourself. The effects are as follows:

1、 Implementation method. Since it is difficult to set this thing, do something directly on the background. The layout code is as follows:

2、 The key part is on the selector in the background. The code is as follows:

The annotated place is the original non spaced selector. Here, about padding is directly set for the background, which has a strong effect.

Disadvantages: if the interval is too large, this method has a little defect, that is, clicking on the blank space can also select the tab.

However, for the interval is not very large, it is basically impossible to feel it.

3、 The use of activity is simple:

4、 It turned out to be a linear layout with tablayout and viewpager. Try to nest another relativelayout outside the tablayout. The results show that the text of the tab is not displayed. As for the online order of exchanging addtab and setupwithviewpager, it is also a pit. You can see the display, but it is more outrageous. There are two blanks in the front and two normal ones in the back, It's wonderful anyway.

Finally, you have to deal with it in the adapter and rewrite the following methods. In fact, it may be more reasonable to ensure that the number of tabs is consistent with the number of pages of the viewpager.

The above tab interval setting method (example explanation) based on tablayout is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.

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
分享
二维码
< <上一篇
下一篇>>