BLO9
Kotlin 등 개발 관련 포스팅합니다.
안드로이드 ViewPager 배경색을 자연스럽게 바꿔주는 코드
public class ColorSmoothChangeListener extends ViewPager.SimpleOnPageChangeListener {

    private View contentView;
    private int[]colors;

    public ColorSmoothChangeListener(View contentView, int[] colors) {
        this.contentView = contentView;
        this.colors = colors;
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        if (colors != null && position + 1 < colors.length) {
            contentView.setBackgroundColor(this.getDiffColorLessByPercent(colors[position], colors[position + 1], positionOffset));
        }
    }

    private int getDiffColorLessByPercent(int color, int otherColor, float percent) {
        return Color.rgb(
                Color.red(color) - Math.round((Color.red(color) - Color.red(otherColor)) * percent),
                Color.green(color) - Math.round((Color.green(color) - Color.green(otherColor)) * percent),
                Color.blue(color) - Math.round((Color.blue(color) - Color.blue(otherColor)) * percent)
        );
    }
}