本文整理匯總了Java中android.support.design.widget.TabLayout.getChildCount方法的典型用法代碼示例。如果您正苦於以下問題:Java TabLayout.getChildCount方法的具體用法?Java TabLayout.getChildCount怎麽用?Java TabLayout.getChildCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.design.widget.TabLayout
的用法示例。
在下文中一共展示了TabLayout.getChildCount方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dynamicSetTabLayoutMode
import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
/**
* 動態修改tab的模式
*
* @param tabLayout tabLayout
*/
public static void dynamicSetTabLayoutMode(TabLayout tabLayout) {
int tabTotalWidth = 0;
for (int i = 0; i < tabLayout.getChildCount(); i++) {
final View view = tabLayout.getChildAt(i);
view.measure(0, 0);
tabTotalWidth += view.getMeasuredWidth();
}
if (tabTotalWidth <= MeasureUtils.getScreenSize(tabLayout.getContext()).x) {
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
} else {
tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
}
}
示例2: calculateTabWidth
import android.support.design.widget.TabLayout; //導入方法依賴的package包/類
private static int calculateTabWidth(TabLayout tabLayout) {
int tabWidth = 0;
for (int i = 0; i < tabLayout.getChildCount(); i++) {
final View view = tabLayout.getChildAt(i);
view.measure(0, 0); // 通知父view測量,以便於能夠保證獲取到寬高
tabWidth += view.getMeasuredWidth();
}
return tabWidth;
}