我加標籤動態如果標籤是4,則它是良好的顯示效果,但如果標籤是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" />
雅我正確的嘗試,但當選項卡是超過4它不可見在UI中是正確的 –
看到這個鏈接可能會幫助你[鏈接]( http://stackoverflow.com/questions/31448504/how-to-scroll-tablayout-programatically-android) –
柯Vartthan感謝 –