设置ListView的数据更改只有几行代码,不用说了;
设置title的文字的变化:给ViewPager设置监听器,Viewpager变化的时候,给文字添加渐变,滑动完成后设置文字最终的大小
主要代码如下:
/** * ViewPager切换监听方法 */ public ViewPager.OnPageChangeListener pageListener = new ViewPager.OnPageChangeListener() { @Override public void onPageScrollStateChanged(int arg0) { } /** * 移动时文字的变化 * Viewpager变化的时候,给文字添加渐变 * * option当前位置 offset偏移百分比 arg2偏移值 像素 */ @Override public void onPageScrolled(int option, float offset, int arg2) { if (offset > 0) { TextView left = (TextView) mLinearLayout.getChildAt(option); ArgbEvaluator eva = new ArgbEvaluator(); int color = (Integer) eva.evaluate(offset, resources.getColor(R.color.text_color_blue), resources.getColor(R.color.text_color_shallow)); left.setTextColor(color); left.setTextSize(15 + (int) (10 * offset)); TextView right = (TextView) mLinearLayout.getChildAt(option + 1); ArgbEvaluator eva2 = new ArgbEvaluator(); int color2 = (Integer) eva2.evaluate(1 - offset, resources.getColor(R.color.text_color_blue), resources.getColor(R.color.text_color_shallow)); right.setTextColor(color2); left.setTextSize(15 + (int) (10 * (1 - offset))); eva = null; eva2 = null; } } @Override public void onPageSelected(int position) { mViewpager.setCurrentItem(position); selectTab(position);//滑动完成后的文字变化 selectIndex = position; } };
/** * 选择后的标题栏里面的文字 */ private void selectTab(int tab_postion) { //判断是否选中 for (int i = 0; i < mLinearLayout.getChildCount(); i++) { View checkView = mLinearLayout.getChildAt(i); boolean ischeck; ((TextView) checkView).setTextColor(resources.getColor(R.color.text_color_shallow)); if (i == tab_postion) { ischeck = true; TextView text = (TextView) checkView; text.setTextSize(20); text.setTextColor(resources.getColor(R.color.text_color_blue)); } else { ischeck = false; TextView text = (TextView) checkView; text.setTextSize(15); } checkView.setSelected(ischeck); } }
这是最终的效果图: