【发布时间】:2021-03-12 15:35:26
【问题描述】:
我目前有一个带有自定义选项卡的选项卡布局。目前,选项卡显示效果很好,唯一的问题是选项卡似乎仅限于选项卡布局选项卡大小,在下一个选项卡之间留有空间。有没有办法使选项卡上的自定义视图与选项卡布局选项卡大小匹配?请告诉我。
custom_tab.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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="50dp">
textview element
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
TabLayout tabLayout = findViewById(R.id.tabLayout);
new TabLayoutMediator(tabLayout, viewPager, new TabLayoutMediator.TabConfigurationStrategy() {
@Override
public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
tab.setCustomView(R.layout.custom_tab);
//get textview and set custom text
//set background color
}
}).attach();
【问题讨论】:
标签: android android-tablayout android-tabs