AUSegment is used to replace APSwitchTab, with related codes reconstructed and the original APIs reserved for smooth scrolling.
If the SDK version is later than 10.0.20, this component supports switching by scrolling a tab. The left and right spacing of each Tab is 14dp:
Scrolling switching is supported when the width of all tabs exceeds the initial width.
When the width of all tabs is less than the initial width, the option indicating whether to equally divide the APIs is provided. By default, equal division is selected.
Sample image
Dependency
See Quick start.
API description
/**
* Reset the tab view.
*/
public void resetTabView(String[] tabNameArray)
/**
* Adjust the position of the selected line at the bottom. Generally, this method is called in the onPageScrolled callback of ViewPager.
*
* @param position The start position.
* @param positionOffset The offset of the start position (in percentage).
*/
public void adjustLinePosition(int position, float positionOffset)
/**
* Select a tab but do not adjust the position of the bottom line, which is suitable for tab switching using ViewPager.
* Implement the selected line at the bottom by calling adjustLinePosition in the onPageScrolled callback of ViewPager.
*
* @param position The position.
*/
public void selectTab(int position)
/**
* Select a tab and adjust the position of the bottom line.<br>
* Used in non-ViewPager tab switching scenarios. The duration of the cutscene before each tab switching interval is 250 ms
*
* @param position The target selected tab.
*/
public void selectTabAndAdjustLine(int position)
/**
* Select a tab and adjust the position of the bottom line.<br>
* Used in non-ViewPager tab switching scenarios. The duration of the cutscene before each tab switching interval is customized.<br>
* If the next animation is enabled before the previous animation finished, the previous animation is immediately terminated. The next animation starts after the final position of the previous animation is located.
*
* @param position The target position.
* @param during The duration of the cutscene before each tab switching interval.
*/
public void selectTabAndAdjustLine(int position, int during)
/**
* Set the tab switching listener.
*
* @param tabSwitchListener
*/
public void setTabSwitchListener(TabSwitchListener tabSwitchListener)
/**
* Add a red dot to the specified position.
* @param view Red dot view.
* @param position
*/
public void addTextRightView(View view, int position)
/**
* Add a red dot to the specified position.
* @param view Red dot view.
* @param params The relative position of the red dot.
* @param position
*/
public void addTextRightView(View view, RelativeLayout.LayoutParams params, int position)
Description of the tab scrolling switching API
To use the scrolling function, set the custom property parameter scroll
to true, for example, adding app:scroll="true"
to the layout file. The scrolling tab supports only the following four APIs. Other APIs are invalid to the scrollable tab.
/**
* Set the tab switching listener.
* @param tabSwitchListener
*/
public void setTabSwitchListener(TabSwitchListener tabSwitchListener)
/**
* Set the data source.
* @param list
*/
public void init(List<ItemCategory> list)
/**
* Set the selected tab.
* @param position
*/
public void setCurrentSelTab(int position)
/**
* Each tab has a fixed left-right spacing of 14dp. An option indicating whether to equally dividing the APIs is provided when the width of all tabs is less than the initial width.
* By default, equal division is selected. If you set this parameter to false, equal division is not allowed.
* @param divideAutoSize
*/
public void setDivideAutoSize(boolean divideAutoSize)
Custom properties
The scroll
property is added to the SDK of a version of 10.0.20 or later.
Property | Purpose | Type |
tabCount | The tab quantity. | Integer |
tab1Text | Tab1 text. | String, Reference |
tab2Text | Tab2 text. | String, Reference |
tab3Text | Tab3 text. | String, Reference |
tab4Text | Tab4 text. | String, Reference |
tabTextArray | The tab text array. | String, Reference |
uniformlySpaced | Whether self-adaptive. | Boolean |
tabTextColor | The text color. | Reference, Color |
tabTextSize | The text size. | Dimension |
buttomLineColor | The color of the bottom line. | Color, Reference |
scroll | Whether to support scrolling. | Boolean |
Code sample
XML
<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="Middle text"
app:tab3Text="Right text"
app:tabCount="3"/>