我一直在开发一个项目,需要使用可滑动的标签以及每个标签的通知文字,设计类似于this。我如何实现这一目标?
我的想法:
我有一个想法是为标签布局添加自定义布局,并在彼此下方添加两个文本视图,但它不会超过标签行!!
关于如何实现它的任何想法?一点点暗示意味着这么多,提前谢谢。
代码:
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.addTab(tabLayout.newTab().setText("In Circle"));
tabLayout.addTab(tabLayout.newTab().setText("You"));
tabLayout.addTab(tabLayout.newTab().setText("Request"));
XML:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/top_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<include
android:id="@+id/bottom_item"
layout="@layout/swipe_tab_header"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_above="@+id/tabs"
android:layout_alignParentTop="true" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
style="@style/MyCustomTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/viewpager"
android:layout_marginBottom="5dp"
app:tabGravity="fill"
app:tabMaxWidth="0dp" />
<RelativeLayout
android:id="@+id/horizontal_slide_relative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tabs">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_item"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<include
android:id="@+id/bottom_item"
layout="@layout/tab_like_view_new"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
答案 0 :(得分:0)
我想最简单的方法是在TabLayout之上设置一个LinearLayout
。
跟随伪xml之类的东西,你使用“margin_top”来正确调整数字:
<FrameLayout>
<android.support.design.widget.TabLayout height=48dp/>
<LinearLayout margin_top=24dp>
<TextView
layout_weight = 1
background="circle"/> // add here your floating numbers
<TextView
layout_weight = 1
background="circle"/> // add here your floating numbers
<TextView
layout_weight = 1
background="circle"/> // add here your floating numbers
</LinearLayout>
</FrameLayout>