AUSegment replaces the APSwitchTab control. The code has been refactored, but it retains the original interfaces and supports smooth scrolling.
In versions 10.0.20 and later, this component supports scrollable tab switching. Each tab has 14 dp of space on its left and right sides.
If the total width of all tabs exceeds the initial width, you can scroll to switch between them.
If the total width of all tabs is less than the initial width, the tabs are spaced evenly by default.
Preview

API reference
/**
* Resets the tab view.
*/
public void resetTabView(String[] tabNameArray)
/**
* Adjusts the position of the bottom selection line.
* This method is typically called in the onPageScrolled callback of a ViewPager.
*
* @param position The starting position.
* @param positionOffset The offset from the starting position, as a percentage.
*/
public void adjustLinePosition(int position, float positionOffset)
/**
* Selects a tab without adjusting the bottom line position.
* This is suitable for tab switching in a ViewPager.
* The bottom selection line is adjusted by calling adjustLinePosition in the onPageScrolled callback of the ViewPager.
*
* @param position The position of the tab.
*/
public void selectTab(int position)
/**
* Selects a tab and adjusts the bottom line position.<br>
* This is used for tab switching scenarios that do not involve a ViewPager. The transition animation time between tabs is 250 ms.
*
* @param position The target tab to select.
*/
public void selectTabAndAdjustLine(int position)
/**
* Selects a tab and adjusts the bottom line position.<br>
* This is used for tab switching scenarios that do not involve a ViewPager. You can specify the transition animation time between tabs.<br>
* If a new animation starts before the previous one finishes, the previous animation stops immediately. The new animation starts from the final position of the previous one.
*
* @param position The target position.
* @param during The transition animation time between tabs.
*/
public void selectTabAndAdjustLine(int position, int during)
/**
* Sets the tab switch listener.
*
* @param tabSwitchListener
*/
public void setTabSwitchListener(TabSwitchListener tabSwitchListener)
/**
* Adds a red dot at a specified position.
* @param view The red dot view.
* @param position
*/
public void addTextRightView(View view, int position)
/**
* Adds a red dot at a specified position.
* @param view The red dot.
* @param params The relative layout parameters of the red dot.
* @param position
*/
public void addTextRightView(View view, RelativeLayout.LayoutParams params, int position)API reference for scrollable tab switching
To enable the scroll feature, set the custom `scroll` property to `true`. For example, add `app:scroll="true"` in the layout file. Scrollable tabs support only the following four APIs.
/**
* Sets the tab switch listener.
* @param tabSwitchListener
*/
public void setTabSwitchListener(TabSwitchListener tabSwitchListener)
/**
* Sets the data source.
* @param list
*/
public void init(List<ItemCategory> list)
/**
* Sets the selected tab.
* @param position
*/
public void setCurrentSelTab(int position)
/**
* The space on the left and right of each tab is fixed at 14 dp.
* If the total width of all tabs is less than the initial width, this method determines whether to space them evenly.
* By default, tabs are spaced evenly. Set this parameter to false to disable even spacing.
* @param divideAutoSize
*/
public void setDivideAutoSize(boolean divideAutoSize)Custom properties
The `scroll` property is available in versions 10.0.20 and later.
Property | Usage | Type |
tabCount | Number of tabs | integer |
tab1Text | Text for Tab1 | string, reference |
tab2Text | Tab 1 text | string, reference |
tab3Text | Text for Tab3 | string, reference |
tab4Text | Text for Tab4 | string, reference |
tabTextArray | Text array for tabs | string, reference |
uniformlySpaced | Whether to space tabs evenly | boolean |
tabTextColor | Text color | reference, color |
tabTextSize | Text size | dimension |
buttomLineColor | Bottom line color | color, reference |
scroll | Whether scrolling is supported | boolean |
Code example
XML example:
<com.alipay.mobile.antui.segement.AUSegment
android:id="@+id/switchtab_three"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
app:tab1Text="Left Text"
app:tab2Text="Center Text"
app:tab3Text="Right Text"
app:tabCount="3"/>