【发布时间】:2016-10-17 14:17:58
【问题描述】:
如果 tab 为 4,我动态添加 tab,那么它显示得很好,但如果 tab 是 2 或 3,那么它不是与父匹配的脚。
代码
public void setUpTab(TabLayout tabLayout, String count, String typeId) {
TabLayout.Tab tab = tabLayout.newTab();
RelativeLayout relativeLayout = (RelativeLayout)
LayoutInflater.from(this).inflate(R.layout.custom_tab, tabLayout, false);
TextView tabTextView = (TextView) relativeLayout.findViewById(R.id.txt_tab);
tabTextView.setText(count);
tab.setTag(typeId);
tab.setCustomView(tabTextView);
tabLayout.addTab(tab);
}
Xml 代码:
<android.support.design.widget.TabLayout
android:id="@+id/tabsRoleType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/com_facebook_likeboxcountview_border_radius"
app:tabBackground="@drawable/tab_rounded_background"
app:tabGravity="fill"
app:tabIndicatorHeight="0dp"
app:tabSelectedTextColor="@color/WhiteColor"
app:tabTextAppearance="@style/TextAppearance.Design.Tab"
app:tabTextColor="@color/BlackColor" />
【问题讨论】: