本文主要介绍TabLayout的几种常见用法:与ViewPager的结合使用、把条目变成图片,去除下划线、仿微信询问(仿微信功能可能有点悬)...我想到的是用染色来实现,试试吧..(。・`ω´・)
一、给TabLayout添加中间分隔线
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/vp"
>
<android.support.design.widget.TabLayout
android:id="@+id/tabl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.v4.view.ViewPager>
//在TabLayot中添加分隔线, 疑问为什么获取到的是线性布局?
LinearLayoutlinearLayout=(LinearLayout)tabLayout.getChildAt(0);
linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
linearLayout.setDividerDrawable(ContextCompat.getDrawable(this,
R.drawable.layout_divider_vertical));
linearLayout.setDividerPadding(35); // 间隔线的高度,值越大线越短.
Tab tab = tabLayout.newTab();
tab.setText(list_title.get(0));
tabLayout.addTab(tab);
-------------------------------------------------------------------------
@NonNull
public Tab newTab() {
Tab tab = sTabPool.acquire();
if (tab == null) {
tab = new Tab();
}
tab.mParent = this;
tab.mView = createTabView(tab);
return tab;
}
-------------------------------------------------------------------------
private TabView createTabView(@NonNull final Tab tab) {
TabView tabView = mTabViewPool != null ? mTabViewPool.acquire() : null;
if (tabView == null) {
tabView = new TabView(getContext());
}
tabView.setTab(tab);
tabView.setFocusable(true);
tabView.setMinimumWidth(getTabMinWidth());
return tabView;
}
-------------------------------------------------------------------------
class TabView extends LinearLayout implements OnLongClickListener
网友评论