gpt4 book ai didi

android - 像屏幕保护程序一样更改渐变颜色?

转载 作者:太空宇宙 更新时间:2023-11-03 12:56:07 25 4
gpt4 key购买 nike

你好 friend 我想像下图一样改变渐变的颜色。我尝试了这么多天,但没有运气。你能帮助我吗?提前致谢!

enter image description here

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

最佳答案

这可以通过逐帧动画来实现。在您的 Activity 中编写以下代码:

 @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帧的图片

sunset

关于android - 像屏幕保护程序一样更改渐变颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20064647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com