7

如果有人能向我解释为什么这样做,我将不胜感激:

private void startAnimating() {
    TextView logo1 = (TextView) findViewById(R.id.Shizzle);   
        final Animation fade1 = new AlphaAnimation(0.0f, 1.0f);  
        fade1.setDuration(3000);
        logo1.startAnimation(fade1);
        }

但这对我根本不起作用:

private void startAnimating() {
    TextView logo1 = (TextView) findViewById(R.id.Shizzle);   
        Animation fade1 = AnimationUtils.loadAnimation(this,R.anim.fade_in);  
    logo1.startAnimation(fade1);    
    }

与上面关联的fade_in.xml是:

    <?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/android"
    android:shareInterpolator="false">
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:duration="3000">
    </alpha>

谢谢你的帮助!

4

1 回答 1

13

对我有用:在文件夹/res/anim - fadein.xmlfadeout.xml中创建两个文件

淡入:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <alpha
        android:duration="500"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" >
    </alpha>

</set>

消退:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <alpha
        android:duration="200"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" >
    </alpha>

</set>

初始化代码:

Animation animFadeIn, animFadeOut;
...
animFadeIn=AnimationUtils.loadAnimation(this, R.anim.fadein);
animFadeOut=AnimationUtils.loadAnimation(this, R.anim.fadeout);

... 使用:

case R.id.imgBtnShowContent:
    rlOrderBtns.startAnimation(animFadeIn);
    rlOrderBtns.setVisibility(View.VISIBLE);
break;

case R.id.imgBtnHideContent:
    rlOrderBtns.startAnimation(animFadeOut);
    rlOrderBtns.setVisibility(View.INVISIBLE);
break;
于 2013-01-04T06:22:27.983 回答