Change color of gradient like ScreenSaver?

android, android-layout, colors, linear-gradients

Solution

This can be achieved by frame by frame animation.In your activity write below code:

 @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();

 }

make 1 xml in drawable folder named as anim_fbyf.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>

you can set duration and add no of frames as per your need.

I have added 13 frames(or gif images) and set duration to 350 milliseconds.

output:

below is the image having 13 frames

Problem

hello friends i want to change color of gradient like below image. m trying from so many days but no luck. can you help me? Thanks in advance! i can draw a color with gradient LinearLayout but i want to change this color at runtime.

Original source

Related problems