2

Actually I am trying to fade out one image and bring another one as a type of animation

public void fade(View view){

    ImageView harsh = findViewById(R.id.harshView);
    harsh.animate().alpha(0f).setDuration(2000);
    ImageView diksha= findViewById(R.id.dikshaView);
    diksha.animate().alpha(1f).setDuration(2000);

}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
harsh
  • 21
  • 2
  • If you're trying to replace an image, this can be easily done by `transistionDrawables` check https://stackoverflow.com/a/29460979/9263083 – sanoJ Jul 01 '19 at 08:28

2 Answers2

2

I had the same Error . I realized that the error "0f" doesn't refer to the code that you have written in the MainActivity.java ,,, however it refers to the activity_main.xml>select the picture you are trying to fade in/out>Attributes>alpha ... in this alpha: the input doesn't require "f" after the number , remove the "f" and the error disappears ,the "f" which stands for float is only expected in the MainActivity.java code .

Dharman
  • 30,962
  • 25
  • 85
  • 135
0

'0f' is incompatible with attribute alpha (attr) float. error: failed linking file resources

The error isn't from your code but from your xml animation file. Try checking for the error either in res/anim or res/animator

Actually I am trying to fade out one image and bring another one as a type of animation

Your code is just slightly need to modified to make it work. You just need to set the second image alpha to 0. Something like this:

public void fade(View view) {
    ImageView harsh = findViewById(R.id.harshView);
    harsh.animate().alpha(0f).setDuration(2000);
    ImageView diksha= findViewById(R.id.dikshaView);
    diksha.setAlpha(0f);
    diksha.animate().alpha(1f).setDuration(2000);
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96