Viewpager+Fragment滑动更改ListView数据和设置title文字的变化

设置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);
    }
}

这是最终的效果图:

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值