首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >改变像ScreenSaver这样的渐变颜色?

改变像ScreenSaver这样的渐变颜色?
EN

Stack Overflow用户
提问于 2013-11-19 06:26:28
回答 2查看 1.4K关注 0票数 3

你好,朋友们,我想改变颜色的渐变像下面的图片。我试了这么多天,但没有运气。你能帮帮我吗?提前感谢!

我可以用渐变LinearLayout绘制颜色,但是我想在运行时更改这个颜色。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-11-20 10:43:16

这可以通过一帧一帧的animation.In来实现,您的活动可以在下面编写代码:

代码语言:javascript
复制
 @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的可绘图文件夹中创建1 xml

代码语言:javascript
复制
 <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帧的图像

票数 5
EN

Stack Overflow用户

发布于 2013-11-19 08:10:26

你可以试试这个:

代码语言:javascript
复制
int h = v.getHeight();
ShapeDrawable mDrawable = new ShapeDrawable(new RectShape());
mDrawable.getPaint().setShader(new LinearGradient(0, 0, 0, h, Color.parseColor("#330000FF"), Color.parseColor("#110000FF"), Shader.TileMode.REPEAT));
v.setBackgroundDrawable(mDrawable);

关于getView()重载函数(ListAdapter)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20064647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档