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
所以你可以得到你想要的结果 –