0
Q
設計這樣
A
回答
2
public class CenteringTabLayout extends TabLayout {
private Typeface mTypeface;
public CenteringTabLayout(Context context) {
super(context);
}
public CenteringTabLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CenteringTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
View firstTab = ((ViewGroup) getChildAt(0)).getChildAt(0);
View lastTab = ((ViewGroup) getChildAt(0)).getChildAt(((ViewGroup) getChildAt(0)).getChildCount() - 1);
if(firstTab!=null)
ViewCompat.setPaddingRelative(getChildAt(0), (getWidth()/2) - (firstTab.getWidth()/2), 0, (getWidth()/2) - (lastTab.getWidth()/2), 0);
}
@Override
public void addOnTabSelectedListener(@NonNull OnTabSelectedListener listener) {
super.addOnTabSelectedListener(listener);
}
@Override
public void addTab(@NonNull Tab tab) {
super.addTab(tab);
ViewGroup mainView = (ViewGroup) getChildAt(0);
ViewGroup tabView = (ViewGroup) mainView.getChildAt(tab.getPosition());
int tabChildCount = tabView.getChildCount();
for (int i = 0; i < tabChildCount; i++) {
View tabViewChild = tabView.getChildAt(i);
if (tabViewChild instanceof TextView) {
((TextView) tabViewChild).setTypeface(mTypeface, Typeface.NORMAL);
}
}
}
}
將此居中tablayout粘貼到你的java類中。 使用您的XML設計
0
中心tablayout代替tablayput的,我建議你使用BottomBar
<com.roughike.bottombar.BottomBar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:bb_tabXmlResource="@xml/bottombar_tabs" />
OR
還要檢查BottomNavigation
<it.sephiroth.android.library.bottomnavigation.BottomNavigation
android:id="@+id/BottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:bbn_entries="@menu/bottombar_menu_4items"
app:bbn_scrollEnabled="true"
app:bbn_badgeProvider="@string/bbn_badgeProvider"
app:layout_behavior="@string/bbn_phone_view_behavior" />
相關問題
- 1. 這是什麼樣的設計模式?
- 2. 如何設計這樣的酒吧?
- 3. DBMS設計這樣的廣告網站
- 4. 我想像freecharge這樣的設計
- 5. 像「Interface Builder」這樣的Android設計師?
- 6. 有沒有這樣的設計模式?
- 7. 如何設計這樣的按鈕?
- 8. 這是怎樣的設計模式?
- 9. 我如何在WPF中設計這樣的區域設置
- 10. 我怎樣才能做到這一點的設計
- 11. 有沒有這樣的設計模式?如何調用它?
- 12. 聯軸器過高或可以像這樣設計?
- 13. 爲什麼golang文件結構設計這樣
- 14. 這個例子是什麼樣的Java設計模型?
- 15. JDK的概念,爲什麼它是這樣的設計
- 16. 爲什麼String類是這樣設計的?
- 17. 如何設計一個像這樣的列表視圖行
- 18. 我可以像這樣使用UIAlertController嗎? iOS的設計查詢
- 19. 設計模式:重構代碼,像這樣的
- 20. 這是什麼樣的網絡程序設計語言? <!-- -->
- 21. 什麼樣的設計模式在這裏使用
- 22. 像XNA這樣的設計/僞代碼的聽線程?
- 23. 如何設計這樣的div和菜單
- 24. 如何在sencha touch中設計這樣的面板2
- 25. 我用CSS設計的這個按鈕不會樣式
- 26. 如何在iOS中實現Peek Calendar這樣的日曆設計?
- 27. 你會如何在Ruby中設計這樣的DSL?
- 28. 管理者設計模式有這樣的東西嗎?
- 29. 如何製作像Visual Studio這樣的設計工具?
- 30. 如何設計像Viber這樣的網絡質量指標?
非常好,但我想創造 – Bhupendra
所以你可以得到你想要的結果 –