将 Jake Wharton 的TitlePagerIndicator更改 为在标签之间滑动时产生您在 Google Play 商店中看到的文本淡化效果所需的最少工作量是多少?我认为关键在于修改onDraw()但这需要我弄清楚他的代码和他的数学。如果有更简单的解决方案,我会更喜欢。
我也试过TitlePagerIndicator.setFadingEdgeLength(100),但这似乎没有任何作用。我知道你必须做TitlePagerIndicator.setHorizontalFadingEdgeEnabled(true)但仍然没有任何褪色效果。
以下是基于 Jake 示例之一的代码:
public class SampleTitlesStyledMethods extends BaseSampleActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_titles);
mAdapter = new TestTitleFragmentAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
TitlePageIndicator indicator = (TitlePageIndicator)findViewById(R.id.indicator);
mIndicator = indicator;
indicator.setViewPager(mPager);
final float density = getResources().getDisplayMetrics().density;
indicator.setBackgroundColor(0x18FF0000);
indicator.setFooterColor(0xFFAA2222);
indicator.setFooterLineHeight(1 * density); //1dp
indicator.setFooterIndicatorHeight(3 * density); //3dp
indicator.setFooterIndicatorStyle(IndicatorStyle.Underline);
indicator.setTextColor(0xAA000000);
indicator.setSelectedColor(0xFF000000);
indicator.setSelectedBold(true);
//my code, doesn't seem to do anything though...
indicator.setHorizontalFadingEdgeEnabled(true);
indicator.setFadingEdgeLength(1000);
}
}