我正在寻找一个定制的TabLayout
。中间的Tab
图标需要一个余地来覆盖内容。请看下面的图片。
Tab.setCustomView()
有保证金。但这并没有覆盖内容。由于我不需要任何复杂的滚动功能,我可以使用几个ViewGroups
,TextView
和ImageView
开发我自己的TabLayout。在我必须这样做之前:
任何帮助将不胜感激!
我通过自定义库和浮动操作按钮的组合实现了这一点。图书馆:MagicIndicator on GitHub
我将中间片段的图标设置为空图标,并将浮动操作按钮放在中间以覆盖TabLayout。它看起来像这样:我的活动布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_marginBottom="50dp"
app:layout_behavior="@string/appbar_scrolling_behavior" />
<net.lucode.hackware.magicindicator.MagicIndicator
android:id="@+id/magic_indicator"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/light_gray"
android:layout_gravity="bottom" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_margin="10dp"
app:srcCompat="@drawable/add_icon"
app:backgroundTint="@color/colorPrimary"/>
</android.support.design.widget.CoordinatorLayout>