【发布时间】:2016-03-15 18:12:26
【问题描述】:
我将 SlidingTabLayout 与我自己的自定义选项卡布局一起使用。一切都按预期工作;选项卡正确显示(标题、顺序、颜色等),但是 setDistributeEvenly 在这种情况下不起作用。措辞较长的选项卡比措辞较短的选项卡具有更长的选择指示符。例如,“篮球”的指示符比“高尔夫”长得多。这是我的代码。如您所见,setDistributeEvenly 设置为 true。
ViewPager pager;
ViewPagerAdapter adapter;
SlidingTabLayout tabs;
adapter = new ViewPagerAdapter(getSupportFragmentManager(), 10, this);
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);
tabs = (SlidingTabLayout) findViewById(R.id.tab_layout);
tabs.setCustomTabView(R.layout.custom_tab, R.id.textView2);
tabs.setDistributeEvenly(true);
tabs.setBackgroundColor(getResources().getColor(R.color.red));
tabs.setSelectedIndicatorColors(getResources().getColor(R.color.white));
tabs.setViewPager(pager);
这是我的自定义布局:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/tab_title"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"/>
我尝试将布局宽度和高度设置为 match_parent、wrap_content 和不同“dp”的各种组合,但也无济于事。您在上面看到的填充不会改变指标的长度。
您对为什么 setDistributeEvenly(true) 在这种情况下会失败有任何想法吗?
【问题讨论】:
标签: android android-layout tabs android-custom-view