你好朋友,我想改变像下面的图像渐变的颜色.我试了很多天但没有运气.你能帮助我吗?提前致谢!
我可以使用渐变linearLayout绘制颜色,但我想在运行时更改此颜色.
解决方法:
这可以通过逐帧动画来实现.在你的活动中写下面的代码:
@OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.your_activity_layout); ImageVIEw animation animation = (ImageVIEw)findVIEwByID(R.ID.imageAnimation); animation.setBackgroundResource(R.drawable.anim_fbyf); } @OverrIDe public voID onWindowFocusChanged (boolean hasFocus) { super.onWindowFocusChanged(hasFocus); AnimationDrawable frameAnimation = (AnimationDrawable) animation.getBackground(); if(hasFocus) frameAnimation.start(); else frameAnimation.stop(); }
在名为anim_fbyf.xml的drawable文件夹中创建1 xml
<animation-List xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:oneshot="false"><item androID:drawable="@drawable/frame0" androID:duration="350" /><item androID:drawable="@drawable/frame1" androID:duration="350" /><item androID:drawable="@drawable/frame2" androID:duration="350" /><item androID:drawable="@drawable/frame3" androID:duration="350" /><item androID:drawable="@drawable/frame4" androID:duration="350" /><item androID:drawable="@drawable/frame5" androID:duration="350" /><item androID:drawable="@drawable/frame6" androID:duration="350" /><item androID:drawable="@drawable/frame7" androID:duration="350" /><item androID:drawable="@drawable/frame8" androID:duration="350" /><item androID:drawable="@drawable/frame9" androID:duration="350" /><item androID:drawable="@drawable/frame10" androID:duration="350" /><item androID:drawable="@drawable/frame11" androID:duration="350" /><item androID:drawable="@drawable/frame12" androID:duration="350" /><item androID:drawable="@drawable/frame13" androID:duration="350" /> </animation-List>
您可以根据需要设置持续时间并添加任何帧数.
我添加了13帧(或gif图像)并将持续时间设置为350毫秒.
输出:
下面是具有13帧的图像
总结以上是内存溢出为你收集整理的android – 像ScreenSaver一样改变渐变的颜色?全部内容,希望文章能够帮你解决android – 像ScreenSaver一样改变渐变的颜色?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)