我是靠谱客的博主 明亮雨,这篇文章主要介绍代码记录:textview文字多颜色渐变、imageview图片无限旋转,现在分享给大家,希望可以做个参考。

tv_name = view.findViewById(R.id.tv_music_name);

tv_name.setText("七里香");

LinearGradient mLinearGradient;

float textWidth = tv_name.getPaint().getTextSize() * tv_name.getText().length();

if(ScreenUtils.isPortrait()){

//双色渐变

mLinearGradient = new LinearGradient(0, 0, textWidth, 0,

getResources().getColor(R.color.music_color_portrait_start),

getResources().getColor(R.color.music_color_portrait_end),

Shader.TileMode.CLAMP);

}else{

//多色渐变

int[] colors = new int[]{

getResources().getColor(R.color.music_color_land_start),

getResources().getColor(R.color.music_color_land_mid),

getResources().getColor(R.color.music_color_land_end)};

float[] position = {0f, 0.5f,1.0f};

mLinearGradient = new LinearGradient(0, 0, textWidth, 0,

colors,position, Shader.TileMode.CLAMP);

}

tv_name.getPaint().setShader(mLinearGradient);

//图片旋转动画

iv_circle = view.findViewById(R.id.iv_circle);

ObjectAnimator objectAnimator;

rotate_flag = true;

if (rotate_flag) {

objectAnimator = ObjectAnimator.ofFloat(iv_circle, "rotation", 360f, 0f);

objectAnimator.setRepeatCount(ValueAnimator.INFINITE);

objectAnimator.setInterpolator(new LinearInterpolator()); //匀速

objectAnimator.setDuration(10000).start(); //每一圈动画的时间

}

最后

以上就是明亮雨最近收集整理的关于代码记录:textview文字多颜色渐变、imageview图片无限旋转的全部内容,更多相关代码记录内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部