衰落的文字使用AnimationUtils.loadAnimation的Andr​​oid [英] Fading in text in Android using AnimationUtils.loadAnimation

查看:182
本文介绍了衰落的文字使用AnimationUtils.loadAnimation的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会很感激,如果有人可以给我解释一下为什么这个作品:

I would be very grateful if someone could explain to me why this works:

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);
        }

但是,这并不为我工作在所有的:

But this doesn't work at all for me:

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是:

The fade_in.xml associated with the above is:

    <?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>

感谢您的帮助!     

Thanks for your help!

推荐答案

为我工作: 创建文件夹两种文件的 / RES /阿尼姆 - fadein.xml fadeout.xml

Works for me: Create two file in folder /res/anim - fadein.xml, fadeout.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>

初​​始化code:

initialize code:

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

... 使用:

... using:

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

case R.id.imgBtnHideContent:
    rlOrderBtns.startAnimation(animFadeOut);
    rlOrderBtns.setVisibility(View.INVISIBLE);
break;

这篇关于衰落的文字使用AnimationUtils.loadAnimation的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆